package com.seeyon.apps.gkcwplugin.listener;

import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.xml.sax.InputSource;

import com.itextpdf.xmp.impl.Base64;
import com.seeyon.apps.collaboration.event.CollaborationAffairsAssignedEvent;
import com.seeyon.apps.collaboration.event.CollaborationFinishEvent;
import com.seeyon.apps.gkcwplugin.dao.DealDataDao;
import com.seeyon.apps.gkcwplugin.manager.SyncZDManager;
import com.seeyon.apps.gkcwplugin.po.ChailfPJPO;
import com.seeyon.apps.gkcwplugin.po.ChailfPO;
import com.seeyon.apps.gkcwplugin.po.ChailfSonPO;
import com.seeyon.apps.gkcwplugin.po.ChailfSonVO;
import com.seeyon.apps.gkcwplugin.po.ChailfeiVO;
import com.seeyon.apps.gkcwplugin.po.FapiaoKjPJPO;
import com.seeyon.apps.gkcwplugin.po.FapiaoKjPO;
import com.seeyon.apps.gkcwplugin.po.FapiaoRzPJPO;
import com.seeyon.apps.gkcwplugin.po.FapiaoRzPO;
import com.seeyon.apps.gkcwplugin.po.FapiaoRzSonVO;
import com.seeyon.apps.gkcwplugin.po.FapiaoRzVO;
import com.seeyon.apps.gkcwplugin.po.FinancialDataPO;
import com.seeyon.apps.gkcwplugin.po.FukuanBankVO;
import com.seeyon.apps.gkcwplugin.po.FukuanPJPO;
import com.seeyon.apps.gkcwplugin.po.FukuanPO;
import com.seeyon.apps.gkcwplugin.po.FukuanSonPO;
import com.seeyon.apps.gkcwplugin.po.FukuanSonVO;
import com.seeyon.apps.gkcwplugin.po.FukuanVO;
import com.seeyon.apps.gkcwplugin.po.HetongPJPO;
import com.seeyon.apps.gkcwplugin.po.HetongPO;
import com.seeyon.apps.gkcwplugin.po.HetongSonPO;
import com.seeyon.apps.gkcwplugin.po.HuiKuanPO;
import com.seeyon.apps.gkcwplugin.po.HuiKuanSonPO;
import com.seeyon.apps.gkcwplugin.po.LaowufeiVO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjNbSonVO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjNbVO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjPO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjSonPO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjSonVO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjVO;
import com.seeyon.apps.gkcwplugin.po.PayItemPO;
import com.seeyon.apps.gkcwplugin.po.ZiJinRZPO;
import com.seeyon.apps.gkcwplugin.po.ZiJinRZSonPO;
import com.seeyon.apps.gkcwplugin.util.BaseConnection;
import com.seeyon.apps.gkcwplugin.util.HttpUtils;
import com.seeyon.apps.gkcwplugin.util.SoapsendUtil;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItemPO;
import com.seeyon.ctp.common.po.filemanager.Attachment;
import com.seeyon.ctp.event.EventTriggerMode;
import com.seeyon.ctp.organization.bo.V3xOrgMember;
import com.seeyon.ctp.organization.manager.OrgManager;
import com.seeyon.ctp.util.DateUtil;
import com.seeyon.ctp.util.annotation.ListenEvent;
import com.seeyon.ctp.util.json.JSONUtil;

/**
 * 相关财务表单流程监听类
 * 
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @CopyRightInformation : XXX(公司名称)
 * @Prject:
 * @ApplicationName: GKCW_Plugin
 * @Title: FinanceListener.java
 * @Package: com.seeyon.apps.gkcwplugin.listener
 * @author: wtxx
 * @date: 2023年3月28日 下午2:21:35
 * @version: V1.0
 */
public class FinanceListener {
	private static final Log logger = LogFactory.getLog(FinanceListener.class);
	private SyncZDManager syncZDManager = (SyncZDManager) AppContext.getBean("syncZDManager");
	private DealDataDao dealDataDao = (DealDataDao) AppContext.getBean("dealDataDao");
	private OrgManager orgManager = (OrgManager)AppContext.getBean("orgManager");

	@ListenEvent(event = CollaborationFinishEvent.class, mode = EventTriggerMode.afterCommit)
	public void financeListenerEvent(CollaborationFinishEvent event) {
		logger.info("----------------------------流程结束事件监听");
		String fukuanCode = AppContext.getSystemProperty("gkcwplugin.fukuanCode");
		String chailfCode = AppContext.getSystemProperty("gkcwplugin.chailfCode");
		String laowfCode = AppContext.getSystemProperty("gkcwplugin.laowfCode");
		String fapiaorzCode = AppContext.getSystemProperty("gkcwplugin.fapiaorzCode");
		String neibuzjCode = AppContext.getSystemProperty("gkcwplugin.neibuzjCode");
		String neibuzjNbCode = AppContext.getSystemProperty("gkcwplugin.neibuzjNbCode");
		try {
			// 模板编号，判断是否为相关财务表单流程
			String templateCode = event.getTemplateCode();
			logger.info("--------------------------templateCode:" + templateCode);
			// 由于每个表单可能会存在不同的流程，所以对模板编号进行截取，比如付款审批的模板编号为fkspTemCode01，配置文件只配置fkspTemCode
			if (templateCode == null || "".equals(templateCode)) {
				return;
			}
			int len = templateCode.length() - 2;
			templateCode = templateCode.substring(0, len);
			String sessionId = "";
			if (fukuanCode.equals(templateCode) || chailfCode.equals(templateCode) || laowfCode.equals(templateCode)
					|| fapiaorzCode.equals(templateCode) || neibuzjCode.equals(templateCode)
					|| neibuzjNbCode.equals(templateCode)) {
				logger.info("----------------财务相关表单流程结束-调用浪潮系统登录接口");
				sessionId = syncZDManager.systemInOut();
				logger.info("----------------sessionId:" + sessionId);
			}
			if (sessionId != null && !"".equals(sessionId) && !"null".equals(sessionId)) {
				String formRecordId = event.getSummary().getFormRecordid().toString();
				logger.info("---------------------formrecordid:" + formRecordId);
				Long summaryId = event.getSummaryId();
				// 查询附件表是否有附件
				List<Attachment> attaList = dealDataDao.attachmentList(summaryId.toString(), false);
				// -----付款审批表流程模板编号
				if (fukuanCode.equals(templateCode)) {
					logger.info("-----------------------付款审批表");
					String fkspUrl = AppContext.getSystemProperty("gkcwplugin.fkspUrl");
					// 组装付款审批接口xml参数
					String fkXml = getFukuanXml(formRecordId, sessionId, attaList);
					logger.info("-----------------------付款审批表接口xml参数：" + fkXml);
					// 调用付款审批表接口
					String fkResult = new SoapsendUtil().postSoap(fkXml, fkspUrl);
					logger.info("----------------------付款审批表接口返回信息：" + fkResult);
					// 解析接口返回信息
					if (!"f".equals(fkResult)) {
						String r = getResult(fkResult);
						if (!"true".equals(r)) {// 接口返回失败也保存，后续定时推送
							FinancialDataPO po1 = getFinancialDataPO(formRecordId, summaryId, templateCode);
							dealDataDao.saveFinancialData(po1);
						}
					} else if ("f".equals(fkResult)) {// 调用接口响应不是200
						FinancialDataPO po2 = getFinancialDataPO(formRecordId, summaryId, templateCode);
						dealDataDao.saveFinancialData(po2);
					}

				} else if (chailfCode.equals(templateCode)) {// -------差旅费报销单
					logger.info("-----------------------差旅费报销单");
					String chailfUrl = AppContext.getSystemProperty("gkcwplugin.chlfUrl");
					// 组装差旅费接口xml参数
					String chailfXml = getChailfXml(formRecordId, sessionId, attaList);
					logger.info("-----------------------差旅费接口xml参数：" + chailfXml);
					// 调用差旅费接口
					String chailfResult = new SoapsendUtil().postSoap(chailfXml, chailfUrl);
					logger.info("----------------------差旅费接口返回信息：" + chailfResult);
					// 解析接口返回信息
					if (!"f".equals(chailfResult)) {
						String r = getResult(chailfResult);
						if (!"true".equals(r)) {// 接口返回失败也保存，后续定时推送
							FinancialDataPO po1 = getFinancialDataPO(formRecordId, summaryId, templateCode);
							dealDataDao.saveFinancialData(po1);
						}
					} else if ("f".equals(chailfResult)) {// 调用接口响应不是200
						FinancialDataPO po2 = getFinancialDataPO(formRecordId, summaryId, templateCode);
						dealDataDao.saveFinancialData(po2);
					}

				} else if (laowfCode.equals(templateCode)) {// ---------劳务费发放表
					logger.info("-----------------------劳务费发放表");
					String lwfUrl = AppContext.getSystemProperty("gkcwplugin.lwfUrl");
					// 组装劳务费接口xml参数
					String lwfXml = getLwfXml(formRecordId, sessionId, attaList);
					logger.info("-----------------------劳务费接口xml参数：" + lwfXml);
					// 调用劳务费接口
					String lwfResult = new SoapsendUtil().postSoap(lwfXml, lwfUrl);
					logger.info("----------------------劳务费接口返回信息：" + lwfResult);
					// 解析接口返回信息
					if (!"f".equals(lwfResult)) {
						String r = getResult(lwfResult);
						if (!"true".equals(r)) {// 接口返回失败也保存，后续定时推送
							FinancialDataPO po1 = getFinancialDataPO(formRecordId, summaryId, templateCode);
							dealDataDao.saveFinancialData(po1);
						}
					} else if ("f".equals(lwfResult)) {// 调用接口响应不是200
						FinancialDataPO po2 = getFinancialDataPO(formRecordId, summaryId, templateCode);
						dealDataDao.saveFinancialData(po2);
					}

				} else if (fapiaorzCode.equals(templateCode)) {// --------发票入账单
					logger.info("-----------------------发票入账单");
					String fprzUrl = AppContext.getSystemProperty("gkcwplugin.fprzUrl");
					// 组装发票入账单接口xml参数
					String fprzXml = getFaprzXml(formRecordId, sessionId, attaList);
					logger.info("-----------------------发票入账单接口xml参数：" + fprzXml);
					// 调用发票入账接口
					String fprzResult = new SoapsendUtil().postSoap(fprzXml, fprzUrl);
					logger.info("----------------------发票入账接口返回信息：" + fprzResult);
					// 解析接口返回信息
					if (!"f".equals(fprzResult)) {
						String r = getResult(fprzResult);
						if (!"true".equals(r)) {// 接口返回失败也保存，后续定时推送
							FinancialDataPO po1 = getFinancialDataPO(formRecordId, summaryId, templateCode);
							dealDataDao.saveFinancialData(po1);
						}
					} else if ("f".equals(fprzResult)) {// 调用接口响应不是200
						FinancialDataPO po2 = getFinancialDataPO(formRecordId, summaryId, templateCode);
						dealDataDao.saveFinancialData(po2);
					}

				} else if (neibuzjCode.equals(templateCode)) {// --------内部资金拨付单
					logger.info("-----------------------内部资金拨付单");
					String nbzjUrl = AppContext.getSystemProperty("gkcwplugin.zjbfdUrl");
					// 组装内部资金拨付单接口xml参数
					String nbzjXml = getNeibuzjXml(formRecordId, sessionId, attaList);
					logger.info("-----------------------内部资金拨付单接口xml参数：" + nbzjXml);
					// 调用内部资金拨付单接口
					String nbzjResult = new SoapsendUtil().postSoap(nbzjXml, nbzjUrl);
					logger.info("----------------------内部资金拨付单接口返回信息：" + nbzjResult);
					// 解析接口返回信息
					if (!"f".equals(nbzjResult)) {
						String r = getResult(nbzjResult);
						if (!"true".equals(r)) {// 接口返回失败也保存，后续定时推送
							FinancialDataPO po1 = getFinancialDataPO(formRecordId, summaryId, templateCode);
							dealDataDao.saveFinancialData(po1);
						}
					} else if ("f".equals(nbzjResult)) {// 调用接口响应不是200
						FinancialDataPO po2 = getFinancialDataPO(formRecordId, summaryId, templateCode);
						dealDataDao.saveFinancialData(po2);
					}

				} else if (neibuzjNbCode.equals(templateCode)) {// --------内部资金拨付单-内部路径
					logger.info("-----------------------内部资金拨付单（内部路径）");
					String nbzjNbUrl = AppContext.getSystemProperty("gkcwplugin.zjbfdUrl");
					// 组装内部资金拨付单（内部路径）接口xml参数
					String nbzjNbXml = getNeibuzjNbxml(formRecordId, sessionId, attaList);
					logger.info("-----------------------内部资金拨付单（内部路径）接口xml参数：" + nbzjNbXml);
					// 调用内部资金拨付单接口
					String nbzjNbResult = new SoapsendUtil().postSoap(nbzjNbXml, nbzjNbUrl);
					logger.info("----------------------内部资金拨付单（内部路径）接口返回信息：" + nbzjNbResult);
					// 解析接口返回信息
					if (!"f".equals(nbzjNbResult)) {
						String r = getResult(nbzjNbResult);
						if (!"true".equals(r)) {// 接口返回失败也保存，后续定时推送
							FinancialDataPO po1 = getFinancialDataPO(formRecordId, summaryId, templateCode);
							dealDataDao.saveFinancialData(po1);
						}
					} else if ("f".equals(nbzjNbResult)) {// 调用接口响应不是200
						FinancialDataPO po2 = getFinancialDataPO(formRecordId, summaryId, templateCode);
						dealDataDao.saveFinancialData(po2);
					}

				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	// 解析接口返回的结果
	public String getResult(String result) {
		try {
			// 字符串转xml
			Document doc = DocumentHelper.parseText(result);
			// 获取根节点
			Element root = doc.getRootElement();
			logger.info("-----------------根节点：" + root.getName());
			Iterator iterator = root.element("Body").element("WriteResponse").elementIterator("WriteResult");
			while (iterator.hasNext()) {
				Element element = (Element) iterator.next();
				String r = element.elementTextTrim("Result");
				logger.info("-------------------解析后，Result:" + r);
				if ("true".equals(r)) {
					logger.info("---------------------接口返回成功");
				} else {
					String msg = element.elementTextTrim("Message");
					logger.info("---------------------接口返回失败，异常信息为：" + msg);
				}
				return r;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	// 组装内部资金拨付单（内部路径）接口xml
	public String getNeibuzjNbxml(String formRecordId, String sessionId, List<Attachment> attaList) {
		NeibuZjNbVO vo = dealDataDao.findNeibuZjNbById(Long.valueOf(formRecordId));
		Long id = vo.getId();
		String unit = vo.getUnit();
		String dept = vo.getDept();
		Date riqi = vo.getRiqi();
		String xmnr = vo.getXmnr();// 项目内容
		BigDecimal jerhjxx = vo.getJerhjxx();// 金额总计小写
		String zjjerdx = vo.getZjjerdx();// 总计金额大写
		String moreUnit = vo.getMoreUnit();
		String fkyh = vo.getFkyh();
		String fkyhzh = vo.getFkyhzh();
		String xgfj = vo.getXgfj();
		/* 2023/7/23 新增编号 start */
		String zjbfNbCode = vo.getZjbfNbCode();// 资金拨付款内部路径编号
		/* 2023/7/23 新增编号 end */

		StringBuffer sb = new StringBuffer();
		sb.append(getHeadXml(sessionId));
		// 主对象
		sb.append("<tem:record>");
		sb.append("<tem:JTGKZJBF_NM>" + String.valueOf(id) + "</tem:JTGKZJBF_NM>");
		sb.append("<tem:JTGKZJBF_DWBH>" + unit + "</tem:JTGKZJBF_DWBH>");
		String sj = DateUtil.format(riqi, "yyyy-MM-dd");
		sb.append("<tem:JTGKZJBF_PZRQ>" + sj + "</tem:JTGKZJBF_PZRQ>");
		sb.append("<tem:JTGKZJBF_FJS></tem:JTGKZJBF_FJS>");
		sb.append("<tem:JTGKZJBF_SFNBLJ>1</tem:JTGKZJBF_SFNBLJ>");
		sb.append("<tem:JTGKZJBF_SFZF>0</tem:JTGKZJBF_SFZF>");
		/* 2023/7/23 新增编号 start */
		sb.append("<tem:JTGKZJBF_BY5>" + zjbfNbCode + "</tem:JTGKZJBF_BY5>");
		/* 2023/7/23 新增编号 end */
		// 从对象
		sb.append("<tem:JTGKZJBFMXS>");

		List<NeibuZjNbSonVO> sonList = dealDataDao.findNeibuZjNbSon(Long.valueOf(formRecordId));
		if (sonList != null && sonList.size() > 0) {
			for (NeibuZjNbSonVO sonVO : sonList) {
				sb.append("<tem:JTGKZJBFMX>");
				Long sonId = sonVO.getId();
				Long formmainId = sonVO.getFormmainId();
				String ytsm = sonVO.getYtsm();// 用途说明
				BigDecimal ytjer = sonVO.getYtjer();// 用途金额
				String ytbz = sonVO.getYtbz();// 用途备注
				String skdwmc = sonVO.getSkdwmc();// 收款单位名称
				String skdwkhh = sonVO.getSkdwkhh();// 收款单位开户行
				String skyhid = sonVO.getSkyhid();// 收款银行id
				String skyhzh = sonVO.getSkyhzh();// 收款银行账号
				sb.append("<tem:JTGKZJBFMX_NM>" + String.valueOf(sonId) + "</tem:JTGKZJBFMX_NM>");
				sb.append("<tem:JTGKZJBFMX_ZBNM>" + String.valueOf(id) + "</tem:JTGKZJBFMX_ZBNM>");
				sb.append("<tem:JTGKZJBFMX_XMNR>" + xmnr + "</tem:JTGKZJBFMX_XMNR>");
				sb.append("<tem:JTGKZJBFMX_YTSM>" + ytsm + "</tem:JTGKZJBFMX_YTSM>");
				sb.append("<tem:JTGKZJBFMX_SKDW>" + skdwmc + "</tem:JTGKZJBFMX_SKDW>");
				sb.append("<tem:JTGKZJBFMX_KHH>" + skyhid + "</tem:JTGKZJBFMX_KHH>");
				sb.append("<tem:JTGKZJBFMX_KHHZH>" + skyhzh + "</tem:JTGKZJBFMX_KHHZH>");
				sb.append("<tem:JTGKZJBFMX_JE>" + ytjer + "</tem:JTGKZJBFMX_JE>");
				sb.append("<tem:JTGKZJBFMX_BZ>" + ytbz + "</tem:JTGKZJBFMX_BZ>");
				sb.append("<tem:JTGKZJBFMX_ZHJ>" + jerhjxx + "</tem:JTGKZJBFMX_ZHJ>");
				sb.append("<tem:JTGKZJBFMX_ZHJDX>" + zjjerdx + "</tem:JTGKZJBFMX_ZHJDX>");
				// sb.append("<tem:JTGKZJBFMX_NBDWLJ>"+moreUnit+"</tem:JTGKZJBFMX_NBDWLJ>");
				sb.append("<tem:JTGKZJBFMX_NBDWLJ></tem:JTGKZJBFMX_NBDWLJ>");
				sb.append("<tem:JTGKZJBFMX_FKYH>" + fkyh + "</tem:JTGKZJBFMX_FKYH>");
				sb.append("<tem:JTGKZJBFMX_FKYHZH>" + fkyhzh + "</tem:JTGKZJBFMX_FKYHZH>");
				sb.append("</tem:JTGKZJBFMX>");
			}
		} else {
			sb.append("<tem:JTGKZJBFMX></tem:JTGKZJBFMX>");
		}
		sb.append("</tem:JTGKZJBFMXS>");
		attaList = dealDataDao.attachmentList(xgfj, true);
		String fjXml = getAttaXml(attaList, id);
		sb.append(fjXml);
		sb.append("</tem:record>");
		sb.append("</tem:Write>");
		sb.append("</soap:Body>");
		sb.append("</soap:Envelope>");
		return sb.toString();
	}

	// 组装内部资金拨付单接口xml
	public String getNeibuzjXml(String formRecordId, String sessionId, List<Attachment> attaList) {
		NeibuZjVO vo = dealDataDao.findNeibuZjById(Long.valueOf(formRecordId));
		Long id = vo.getId();
		String unit = vo.getUnit();
		String unitCode = vo.getUnitCode();
		String dept = vo.getDept();
		Date riqi = vo.getRiqi();
		String xmnr = vo.getXmnr();// 项目内容
		BigDecimal jerzjxx = vo.getJerzjxx();// 金额总计小写
		String zjjerdx = vo.getZjjerdx();// 总计金额大写
		String fkyh = vo.getFkyh();// 付款银行 id
		String fkyhzh = vo.getFkyhzh();// 付款银行账户 银行内码
		String xgfj = vo.getXgfj();// 相关附件
		/* 2023/7/23 新增编号 start */
		String xsgCode = vo.getXsgCode();// 响水港编号
		String jtbbCode = vo.getJtbbCode();// 集团本部编号
		/* 2023/7/23 新增编号 end */

		StringBuffer sb = new StringBuffer();
		sb.append(getHeadXml(sessionId));
		// 主对象
		sb.append("<tem:record>");
		sb.append("<tem:JTGKZJBF_NM>" + String.valueOf(id) + "</tem:JTGKZJBF_NM>");
		sb.append("<tem:JTGKZJBF_DWBH>" + unitCode + "</tem:JTGKZJBF_DWBH>");
		String sj = DateUtil.format(riqi, "yyyy-MM-dd");
		sb.append("<tem:JTGKZJBF_PZRQ>" + sj + "</tem:JTGKZJBF_PZRQ>");
		sb.append("<tem:JTGKZJBF_FJS></tem:JTGKZJBF_FJS>");
		sb.append("<tem:JTGKZJBF_SFNBLJ>0</tem:JTGKZJBF_SFNBLJ>");
		sb.append("<tem:JTGKZJBF_SFZF>0</tem:JTGKZJBF_SFZF>");
		/* 2023/7/23 新增编号 start */
		if (xsgCode != null && !"".equals(xsgCode)) {
			sb.append("<tem:JTGKZJBF_BY5>" + xsgCode + "</tem:JTGKZJBF_BY5>");
		} else if (jtbbCode != null && !"".equals(jtbbCode)) {
			sb.append("<tem:JTGKZJBF_BY5>" + jtbbCode + "</tem:JTGKZJBF_BY5>");
		} else {
			sb.append("<tem:JTGKZJBF_BY5></tem:JTGKZJBF_BY5>");
		}
		/* 2023/7/23 新增编号 end */
		// 从对象
		sb.append("<tem:JTGKZJBFMXS>");

		List<NeibuZjSonVO> sonList = dealDataDao.findNeibuZjSon(Long.valueOf(formRecordId));
		if (sonList != null && sonList.size() > 0) {
			for (NeibuZjSonVO sonVO : sonList) {
				sb.append("<tem:JTGKZJBFMX>");
				Long sonId = sonVO.getId();
				Long formmainId = sonVO.getFormmainId();
				String ytsm = sonVO.getYtsm();// 用途说明
				BigDecimal ytjer = sonVO.getYtjer();// 用途金额
				String ytbz = sonVO.getYtbz();// 用途备注
				String skdwmc = sonVO.getSkdwmc();// 收款单位名称
				String skdwCode = sonVO.getSkdwCode();
				String skdwkhh = sonVO.getSkdwkhh();// 收款单位开户行
				String skyhid = sonVO.getSkyhid();// 收款银行id
				String skyhzh = sonVO.getSkyhzh();// 收款银行账号

				sb.append("<tem:JTGKZJBFMX_NM>" + String.valueOf(sonId) + "</tem:JTGKZJBFMX_NM>");
				sb.append("<tem:JTGKZJBFMX_ZBNM>" + String.valueOf(id) + "</tem:JTGKZJBFMX_ZBNM>");
				sb.append("<tem:JTGKZJBFMX_XMNR>" + xmnr + "</tem:JTGKZJBFMX_XMNR>");
				sb.append("<tem:JTGKZJBFMX_YTSM>" + ytsm + "</tem:JTGKZJBFMX_YTSM>");
				sb.append("<tem:JTGKZJBFMX_SKDW>" + skdwCode + "</tem:JTGKZJBFMX_SKDW>");
				sb.append("<tem:JTGKZJBFMX_KHH>" + skyhid + "</tem:JTGKZJBFMX_KHH>");
				sb.append("<tem:JTGKZJBFMX_KHHZH>" + skyhzh + "</tem:JTGKZJBFMX_KHHZH>");
				sb.append("<tem:JTGKZJBFMX_JE>" + ytjer + "</tem:JTGKZJBFMX_JE>");
				sb.append("<tem:JTGKZJBFMX_BZ>" + ytbz + "</tem:JTGKZJBFMX_BZ>");
				sb.append("<tem:JTGKZJBFMX_ZHJ>" + jerzjxx + "</tem:JTGKZJBFMX_ZHJ>");
				sb.append("<tem:JTGKZJBFMX_ZHJDX>" + zjjerdx + "</tem:JTGKZJBFMX_ZHJDX>");
				sb.append("<tem:JTGKZJBFMX_FKYH>" + fkyh + "</tem:JTGKZJBFMX_FKYH>");
				sb.append("<tem:JTGKZJBFMX_FKYHZH>" + fkyhzh + "</tem:JTGKZJBFMX_FKYHZH>");
				sb.append("</tem:JTGKZJBFMX>");
			}
		} else {
			sb.append("<tem:JTGKZJBFMX></tem:JTGKZJBFMX>");
		}

		sb.append("</tem:JTGKZJBFMXS>");
		attaList = dealDataDao.attachmentList(xgfj, true);
		String fjXml = getAttaXml(attaList, id);
		sb.append(fjXml);
		sb.append("</tem:record>");
		sb.append("</tem:Write>");
		sb.append("</soap:Body>");
		sb.append("</soap:Envelope>");
		return sb.toString();
	}

	// 组装差旅费xml参数
	public String getChailfXml(String formRecordId, String sessionId, List<Attachment> attaList) {
		ChailfeiVO vo = dealDataDao.findChailfById(Long.valueOf(formRecordId));
		Long id = vo.getId();
		String unit = vo.getUnit();
		String dept = vo.getDept();
		Date riqi = vo.getRiqi();
		String reason = vo.getReason();// 出差事由
		String sbjerdx = vo.getSbjerdx();// 申报金额大写
		String sfjerdx = vo.getSfjerdx();// 实付金额大写
		BigDecimal fyhj = vo.getFyhj();// 费用合计
		String fkyh = vo.getFkyh();// 付款银行 银行id
		String fkyhzh = vo.getFkyhzh();// 付款银行账号 银行账号
		String gldwbm = vo.getGldwbm();// 关联单位编码
		/* 2023/7/23 新增编号 start */
		String xsgCode = vo.getXsgCode();// 响水港编号
		String xsgwCode = vo.getXsgwCode();// 响水港务编号
		String xsgsjCode = vo.getXsgsjCode();// 响水港三级公司编号
		String jtbbCode = vo.getJtbbCode();// 集团本部编号
		/* 2023/7/23 新增编号 end */
		StringBuffer sb = new StringBuffer();
		sb.append(getHeadXml(sessionId));
		// 主对象
		sb.append("<tem:record>");
		sb.append("<tem:JTGKCLBX_NM>" + String.valueOf(id) + "</tem:JTGKCLBX_NM>");
		sb.append("<tem:JTGKCLBX_DWBH>" + gldwbm + "</tem:JTGKCLBX_DWBH>");
		sb.append("<tem:JTGKCLBX_BMBH>" + dept + "</tem:JTGKCLBX_BMBH>");
		String sj = DateUtil.format(riqi, "yyyy-MM-dd");
		sb.append("<tem:JTGKCLBX_PZRQ>" + sj + "</tem:JTGKCLBX_PZRQ>");
		sb.append("<tem:JTGKCLBX_FJS></tem:JTGKCLBX_FJS>");
		sb.append("<tem:JTGKCLBX_SFZF>0</tem:JTGKCLBX_SFZF>");
		/* 2023/7/23 新增编号 start */
		if (xsgCode != null && !"".equals(xsgCode)) {
			sb.append("<tem:JTGKCLBX_BY5>" + xsgCode + "</tem:JTGKCLBX_BY5>");
		} else if (xsgwCode != null && !"".equals(xsgwCode)) {
			sb.append("<tem:JTGKCLBX_BY5>" + xsgwCode + "</tem:JTGKCLBX_BY5>");
		} else if (xsgsjCode != null && !"".equals(xsgsjCode)) {
			sb.append("<tem:JTGKCLBX_BY5>" + xsgsjCode + "</tem:JTGKCLBX_BY5>");
		} else if (jtbbCode != null && !"".equals(jtbbCode)) {
			sb.append("<tem:JTGKCLBX_BY5>" + jtbbCode + "</tem:JTGKCLBX_BY5>");
		} else {
			sb.append("<tem:JTGKCLBX_BY5></tem:JTGKCLBX_BY5>");
		}
		/* 2023/7/23 新增编号 end */

		// 从对象
		sb.append("<tem:JTGKCLBXMXS>");

		List<ChailfSonVO> sonList = dealDataDao.findChailfSon(Long.valueOf(formRecordId));
		if (sonList != null && sonList.size() > 0) {
			for (ChailfSonVO sonVO : sonList) {
				sb.append("<tem:JTGKCLBXMX>");
				Long sonId = sonVO.getId();
				Date startTime = sonVO.getStartTime();
				Date endTime = sonVO.getEndTime();
				String startPlace = sonVO.getStartPlace();// 起地点
				String endPlace = sonVO.getEndPlace();// 止地点
				String transport = sonVO.getTransport();// 交通方式
				String cclx = sonVO.getCclx();// 出差类型
				BigDecimal jtfwhsj = sonVO.getJtfwhsj();// 交通费为含税价
				BigDecimal jtfser = sonVO.getJtfser();// 交通费税额
				BigDecimal jtfshuil = sonVO.getJtfshuil();// 交通费税率
				BigDecimal csjjtf = sonVO.getCsjjtf();// 城市间交通费
				BigDecimal zsfwhsj = sonVO.getZsfwhsj();// 住宿费未含税价
				BigDecimal zsfshuij = sonVO.getZsfshuij();// 住宿费税金
				BigDecimal zsfshuil = sonVO.getZsfshuil();// 住宿费税率
				BigDecimal zsf = sonVO.getZsf();// 住宿费
				BigDecimal hsbzfts = sonVO.getHsbzfts();// 伙食补助费天数
				int hsts = hsbzfts.intValue();
				BigDecimal hsbzfjer = sonVO.getHsbzfjer();// 伙食补助费金额
				BigDecimal snjtfts = sonVO.getSnjtfts();// 市内交通费天数
				int snts = snjtfts.intValue();
				BigDecimal snjtfjer = sonVO.getSnjtfjer();// 市内交通费金额
				BigDecimal pxfeiwhsj = sonVO.getPxfeiwhsj();// 培训费未含税价
				BigDecimal pxfeisj = sonVO.getPxfeisj();// 培训费税金
				BigDecimal pxfeisl = sonVO.getPxfeisl();// 培训费税率
				BigDecimal pxfei = sonVO.getPxfei();// 培训费
				BigDecimal zhaodf = sonVO.getZhaodf();// 招待费
				BigDecimal otherFee = sonVO.getOtherFee();// 其他费用
				BigDecimal gerenbyj = sonVO.getGerenbyj();// 个人备用金
				String jkr = sonVO.getJkr();// 借款人
				BigDecimal xiaoji = sonVO.getXiaoji();// 小计
				String remark = sonVO.getRemark();// 备注
				sb.append("<tem:JTGKCLBXMX_NM>" + String.valueOf(sonId) + "</tem:JTGKCLBXMX_NM>");
				sb.append("<tem:JTGKCLBXMX_ZBNM>" + String.valueOf(id) + "</tem:JTGKCLBXMX_ZBNM>");
				sb.append("<tem:JTGKCLBXMX_CCSY>" + reason + "</tem:JTGKCLBXMX_CCSY>");
				String kssj = DateUtil.format(startTime, "yyyy-MM-dd");
				String jssj = DateUtil.format(endTime, "yyyy-MM-dd");
				sb.append("<tem:JTGKCLBXMX_KSSJ>" + kssj + "</tem:JTGKCLBXMX_KSSJ>");
				sb.append("<tem:JTGKCLBXMX_JSSJ>" + jssj + "</tem:JTGKCLBXMX_JSSJ>");
				sb.append("<tem:JTGKCLBXMX_KSDD>" + startPlace + "</tem:JTGKCLBXMX_KSDD>");
				sb.append("<tem:JTGKCLBXMX_JSDD>" + endPlace + "</tem:JTGKCLBXMX_JSDD>");
				CtpEnumItemPO ctpEnumItem = dealDataDao.getEnum(transport);
				if (ctpEnumItem != null) {
					sb.append("<tem:JTGKCLBXMX_JTFS>" + ctpEnumItem.getShowvalue() + "</tem:JTGKCLBXMX_JTFS>");
				} else {
					sb.append("<tem:JTGKCLBXMX_JTFS></tem:JTGKCLBXMX_JTFS>");
				}
				CtpEnumItemPO cclxItem = dealDataDao.getEnum(cclx);
				if (cclx != null) {
					sb.append("<tem:JTGKCLBXMX_CCLB>" + cclxItem.getShowvalue() + "</tem:JTGKCLBXMX_CCLB>");
				} else {
					sb.append("<tem:JTGKCLBXMX_CCLB></tem:JTGKCLBXMX_CCLB>");
				}

				sb.append("<tem:JTGKCLBXMX_KCJTBHS>" + jtfwhsj + "</tem:JTGKCLBXMX_KCJTBHS>");
				sb.append("<tem:JTGKCLBXMX_KCJTSE>" + jtfser + "</tem:JTGKCLBXMX_KCJTSE>");
				sb.append("<tem:JTGKCLBXMX_KCJTSL>" + jtfshuil + "</tem:JTGKCLBXMX_KCJTSL>");
				sb.append("<tem:JTGKCLBXMX_KCJTHSJE>" + csjjtf + "</tem:JTGKCLBXMX_KCJTHSJE>");
				sb.append("<tem:JTGKCLBXMX_ZSBHS>" + zsfwhsj + "</tem:JTGKCLBXMX_ZSBHS>");
				sb.append("<tem:JTGKCLBXMX_ZSSE>" + zsfshuij + "</tem:JTGKCLBXMX_ZSSE>");
				sb.append("<tem:JTGKCLBXMX_ZSSL>" + zsfshuil + "</tem:JTGKCLBXMX_ZSSL>");
				sb.append("<tem:JTGKCLBXMX_ZSHSJE>" + zsf + "</tem:JTGKCLBXMX_ZSHSJE>");
				sb.append("<tem:JTGKCLBXMX_CBTS>" + hsts + "</tem:JTGKCLBXMX_CBTS>");
				sb.append("<tem:JTGKCLBXMX_CBJE>" + hsbzfjer + "</tem:JTGKCLBXMX_CBJE>");
				sb.append("<tem:JTGKCLBXMX_SNJTTS>" + snts + "</tem:JTGKCLBXMX_SNJTTS>");
				sb.append("<tem:JTGKCLBXMX_SNJTJE>" + snjtfjer + "</tem:JTGKCLBXMX_SNJTJE>");
				sb.append("<tem:JTGKCLBXMX_PXFBHS>" + pxfeiwhsj + "</tem:JTGKCLBXMX_PXFBHS>");
				sb.append("<tem:JTGKCLBXMX_PXFSE>" + pxfeisj + "</tem:JTGKCLBXMX_PXFSE>");
				sb.append("<tem:JTGKCLBXMX_PXFSL>" + pxfeisl + "</tem:JTGKCLBXMX_PXFSL>");
				sb.append("<tem:JTGKCLBXMX_PXFHSJE>" + pxfei + "</tem:JTGKCLBXMX_PXFHSJE>");
				sb.append("<tem:JTGKCLBXMX_ZDF>" + zhaodf + "</tem:JTGKCLBXMX_ZDF>");
				sb.append("<tem:JTGKCLBXMX_QTFY>" + otherFee + "</tem:JTGKCLBXMX_QTFY>");
				sb.append("<tem:JTGKCLBXMX_GRBYJ>" + gerenbyj + "</tem:JTGKCLBXMX_GRBYJ>");
				sb.append("<tem:JTGKCLBXMX_JKR>" + jkr + "</tem:JTGKCLBXMX_JKR>");
				sb.append("<tem:JTGKCLBXMX_HJJE>" + xiaoji + "</tem:JTGKCLBXMX_HJJE>");
				sb.append("<tem:JTGKCLBXMX_BZ>" + remark + "</tem:JTGKCLBXMX_BZ>");
				sb.append("<tem:JTGKCLBXMX_ZHJJE>" + fyhj + "</tem:JTGKCLBXMX_ZHJJE>");
				sb.append("<tem:JTGKCLBXMX_ZSBJE>" + sbjerdx + "</tem:JTGKCLBXMX_ZSBJE>");
				sb.append("<tem:JTGKCLBXMX_ZZFJE>" + sfjerdx + "</tem:JTGKCLBXMX_ZZFJE>");
				sb.append("<tem:JTGKCLBXMX_FKYH>" + fkyh + "</tem:JTGKCLBXMX_FKYH>");
				sb.append("<tem:JTGKCLBXMX_FKYHZH>" + fkyhzh + "</tem:JTGKCLBXMX_FKYHZH>");
				sb.append("</tem:JTGKCLBXMX>");
			}
		} else {
			sb.append("<tem:JTGKCLBXMX></tem:JTGKCLBXMX>");
		}

		sb.append("</tem:JTGKCLBXMXS>");
		String fjXml = getAttaXml(attaList, id);
		sb.append(fjXml);
		sb.append("</tem:record>");
		sb.append("</tem:Write>");
		sb.append("</soap:Body>");
		sb.append("</soap:Envelope>");
		return sb.toString();
	}

	// 组装发票入账xml参数
	public String getFaprzXml(String formRecordId, String sessionId, List<Attachment> attaList) {
		FapiaoRzVO fpRzVO = dealDataDao.findFapiaoRzById(Long.valueOf(formRecordId));
		Long id = fpRzVO.getId();
		String unit = fpRzVO.getUnit();
		String unitCode = fpRzVO.getUnitCode();
		Date riqi = fpRzVO.getRiqi();
		BigDecimal htjerhj = fpRzVO.getHtjerhj();// 合同金额合计
		String xmnr = fpRzVO.getXmnr();// 项目内容
//		String xmnrtwo=fpRzVO.getXmnrtwo();
		String newContent = "";
//		if (xmnr!=null&&!"".equals(xmnr)) {
		newContent = xmnr;
//		}else if (xmnrtwo!=null&&!"".equals(xmnrtwo)) {
//			newContent=xmnrtwo;
//		}
		BigDecimal bhsjerzj = fpRzVO.getBhsjerzj();// 不含税金额总计
		BigDecimal serzj = fpRzVO.getSerzj();// 税额总计
		BigDecimal jszj = fpRzVO.getJszj();// 价税总计
		String xgfj = fpRzVO.getXgfj();// 相关附件
		String gldwbm = fpRzVO.getGldwbm();
		/* 2023/7/23 新增编号 start */
		String xsgCode = fpRzVO.getXsgCode();// 响水港编号
		String xsgwCode = fpRzVO.getXsgwCode();// 响水港务编号
		String xsgsjCode = fpRzVO.getXsgsjCode();// 响水港三级公司编号
		String jtbbCode = fpRzVO.getJtbbCode();// 集团本部编号
		/* 2023/7/23 新增编号 end */

		StringBuffer sb = new StringBuffer();
		sb.append(getHeadXml(sessionId));
		// 主对象
		sb.append("<tem:record>");
		sb.append("<tem:JTGKFPRZ_NM>" + String.valueOf(id) + "</tem:JTGKFPRZ_NM>");
		sb.append("<tem:JTGKFPRZ_DWBH>" + gldwbm + "</tem:JTGKFPRZ_DWBH>");
		String sj = DateUtil.format(riqi, "yyyy-MM-dd");
		sb.append("<tem:JTGKFPRZ_PZRQ>" + sj + "</tem:JTGKFPRZ_PZRQ>");
		sb.append("<tem:JTGKFPRZ_FJS></tem:JTGKFPRZ_FJS>");
		sb.append("<tem:JTGKFPRZ_SFZF>0</tem:JTGKFPRZ_SFZF>");
		/* 2023/7/23 新增编号 start */
		if (xsgCode != null && !"".equals(xsgCode)) {
			sb.append("<tem:JTGKFPRZ_BY5>" + xsgCode + "</tem:JTGKFPRZ_BY5>");
		} else if (xsgwCode != null && !"".equals(xsgwCode)) {
			sb.append("<tem:JTGKFPRZ_BY5>" + xsgwCode + "</tem:JTGKFPRZ_BY5>");
		} else if (xsgsjCode != null && !"".equals(xsgsjCode)) {
			sb.append("<tem:JTGKFPRZ_BY5>" + xsgsjCode + "</tem:JTGKFPRZ_BY5>");
		} else if (jtbbCode != null && !"".equals(jtbbCode)) {
			sb.append("<tem:JTGKFPRZ_BY5>" + jtbbCode + "</tem:JTGKFPRZ_BY5>");
		} else {
			sb.append("<tem:JTGKFPRZ_BY5></tem:JTGKFPRZ_BY5>");
		}
		/* 2023/7/23 新增编号 end */
		// 从对象
		sb.append("<tem:JTGKFPRZMXS>");

		// 查询发票入账单子表
		List<FapiaoRzSonVO> fpSonList = dealDataDao.findFapiaoRzSon(Long.valueOf(formRecordId));
		if (fpSonList != null && fpSonList.size() > 0) {
			for (FapiaoRzSonVO sonVO : fpSonList) {
				sb.append("<tem:JTGKFPRZMX>");
				Long sonId = sonVO.getId();
				Long formmainId = sonVO.getFormmainId();
				String bxxmnr = sonVO.getBxxmnr();// 报销项目内容
				String xmcode = sonVO.getBxxmnrCode();
				String dept = sonVO.getDept();
				String fplx = sonVO.getFplx();// 发票类型
				String fphm = sonVO.getFphm();// 发票号码
				String fpdm = sonVO.getFpdm();// 发票代码
				Date kprq = sonVO.getKprq();
				BigDecimal shuier = sonVO.getShuier();// 税额
				BigDecimal bhsjer = sonVO.getBhsjer();// 不含税金额
				BigDecimal shuil = sonVO.getShuil();// 税率
				BigDecimal jshj = sonVO.getJshj();// 价税合计
				String xhdwmc = sonVO.getXhdwmc();// 销货单位名称
				String xhdwsh = sonVO.getXhdwsh();// 销货单位税号
				String xhfkhh = sonVO.getXhfkhh();// 销货方开户行
				String xhfzh = sonVO.getXhfzh();// 销货方银行账号
				String xhfyhid = sonVO.getXhfyhid();// 销货方银行id
				sb.append("<tem:JTGKFPRZMX_NM>" + String.valueOf(sonId) + "</tem:JTGKFPRZMX_NM>");
				sb.append("<tem:JTGKFPRZMX_ZBNM>" + String.valueOf(id) + "</tem:JTGKFPRZMX_ZBNM>");
				sb.append("<tem:JTGKFPRZMX_XMNR>" + newContent + "</tem:JTGKFPRZMX_XMNR>");
				sb.append("<tem:JTGKFPRZMX_XHDW>" + xhdwmc + "</tem:JTGKFPRZMX_XHDW>");
				sb.append("<tem:JTGKFPRZMX_XHDWSH>" + xhdwsh + "</tem:JTGKFPRZMX_XHDWSH>");
				sb.append("<tem:JTGKFPRZMX_XHKHH>" + xhfyhid + "</tem:JTGKFPRZMX_XHKHH>");
				sb.append("<tem:JTGKFPRZMX_XHYHZH>" + xhfzh + "</tem:JTGKFPRZMX_XHYHZH>");
				sb.append("<tem:JTGKFPRZMX_BMBH>" + dept + "</tem:JTGKFPRZMX_BMBH>");
				sb.append("<tem:JTGKFPRZMX_JTXMNR>" + xmcode + "</tem:JTGKFPRZMX_JTXMNR>");
				CtpEnumItemPO ctpEnumItem = dealDataDao.getEnum(fplx);
				sb.append("<tem:JTGKFPRZMX_FPLX>" + ctpEnumItem.getShowvalue() + "</tem:JTGKFPRZMX_FPLX>");
				sb.append("<tem:JTGKFPRZMX_FPDM>" + fpdm + "</tem:JTGKFPRZMX_FPDM>");
				sb.append("<tem:JTGKFPRZMX_FPHM>" + fphm + "</tem:JTGKFPRZMX_FPHM>");
				sb.append("<tem:JTGKFPRZMX_BHSJE>" + bhsjer + "</tem:JTGKFPRZMX_BHSJE>");
				if (shuier != null && !"".equals(shuier)) {
					sb.append("<tem:JTGKFPRZMX_SE>" + shuier + "</tem:JTGKFPRZMX_SE>");
				}
				sb.append("<tem:JTGKFPRZMX_SL>" + shuil + "</tem:JTGKFPRZMX_SL>");
				sb.append("<tem:JTGKFPRZMX_HSJE>" + jshj + "</tem:JTGKFPRZMX_HSJE>");
				sb.append("<tem:JTGKFPRZMX_HJ>" + jszj + "</tem:JTGKFPRZMX_HJ>");
				sb.append("</tem:JTGKFPRZMX>");
			}
		} else {
			sb.append("<tem:JTGKFPRZMX></tem:JTGKFPRZMX>");
		}

		sb.append("</tem:JTGKFPRZMXS>");
		attaList = dealDataDao.attachmentList(xgfj, true);
		String fjXml = getAttaXml(attaList, id);
		sb.append(fjXml);
		sb.append("</tem:record>");
		sb.append("</tem:Write>");
		sb.append("</soap:Body>");
		sb.append("</soap:Envelope>");
		return sb.toString();
	}

	// 拼接付款审批xml参数
	public String getFukuanXml(String formRecordId, String sessionId, List<Attachment> attaList) {
		FukuanVO fukuanVO = dealDataDao.findFukuanById(Long.valueOf(formRecordId));
		Long id = fukuanVO.getId();
		String unitCode = fukuanVO.getUnitCode();
		String dept = fukuanVO.getDept();
		Date riqi = fukuanVO.getRiqi();
		String content = fukuanVO.getContent();
		BigDecimal zerhjxx = fukuanVO.getZerhjxx();
		String zjjerdx = fukuanVO.getZjjerdx();
		String xgfj = fukuanVO.getXgfj();// 相关附件
		/* 2023/7/23 新增编号 start */
		String xsgCode = fukuanVO.getXsgCode();// 响水港编号
		String xsgwCode = fukuanVO.getXsgwCode();// 响水港务编号
		String xsgsjCode = fukuanVO.getXsgsjCode();// 响水港三级公司编号
		String jtbbCode = fukuanVO.getJtbbCode();// 集团本部编号
		/* 2023/7/23 新增编号 end */

		StringBuffer sb = new StringBuffer();
		sb.append(getHeadXml(sessionId));
		// 主对象
		sb.append("<tem:record>");
		sb.append("<tem:JTGKFKSP_NM>" + String.valueOf(id) + "</tem:JTGKFKSP_NM>");
		sb.append("<tem:JTGKFKSP_DWBH>" + unitCode + "</tem:JTGKFKSP_DWBH>");
		String sj = DateUtil.format(riqi, "yyyy-MM-dd");
		sb.append("<tem:JTGKFKSP_PZRQ>" + sj + "</tem:JTGKFKSP_PZRQ>");
		sb.append("<tem:JTGKFKSP_FJS></tem:JTGKFKSP_FJS>");
		sb.append("<tem:JTGKFKSP_SFZF>0</tem:JTGKFKSP_SFZF>");
		/* 2023/7/23 新增编号 start */
		if (xsgCode != null && !"".equals(xsgCode)) {
			sb.append("<tem:JTGKFKSP_BY5>" + xsgCode + "</tem:JTGKFKSP_BY5>");
		} else if (xsgwCode != null && !"".equals(xsgwCode)) {
			sb.append("<tem:JTGKFKSP_BY5>" + xsgwCode + "</tem:JTGKFKSP_BY5>");
		} else if (xsgsjCode != null && !"".equals(xsgsjCode)) {
			sb.append("<tem:JTGKFKSP_BY5>" + xsgsjCode + "</tem:JTGKFKSP_BY5>");
		} else if (jtbbCode != null && !"".equals(jtbbCode)) {
			sb.append("<tem:JTGKFKSP_BY5>" + jtbbCode + "</tem:JTGKFKSP_BY5>");
		} else {
			sb.append("<tem:JTGKFKSP_BY5></tem:JTGKFKSP_BY5>");
		}
		/* 2023/7/23 新增编号 end */
		// 从对象集合
		sb.append("<tem:JTGKFKSPMXS>");

		// 查询付款审批表单子表
		List<FukuanSonVO> sonList = dealDataDao.findFukuanSon(Long.valueOf(formRecordId));
		if (sonList != null && sonList.size() > 0) {
			for (FukuanSonVO fukuanSonVO : sonList) {
				sb.append("<tem:JTGKFKSPMX>");
				Long sonId = fukuanSonVO.getId();
				String ytsm = fukuanSonVO.getYtsm();// 用途说明
				String skdw = fukuanSonVO.getSkdw();// 收款单位
				String skdwid = fukuanSonVO.getSkdwCode();// 收款单位编码
				String skyhid = fukuanSonVO.getSkyhid();// 收款银行 id
				String skzh = fukuanSonVO.getSkzh();// 收款账号
				String sknm = fukuanSonVO.getSknm();// 收款银行数据内码
				// String khhjzh=fukuanSonVO.getKhhjzh();//开户行及账号
				BigDecimal ytjer = fukuanSonVO.getYtjer();// 用途金额
				String ytbz = fukuanSonVO.getYtbz();// 用途备注
				sb.append("<tem:JTGKFKSPMX_NM>" + String.valueOf(sonId) + "</tem:JTGKFKSPMX_NM>");
				sb.append("<tem:JTGKFKSPMX_ZBNM>" + String.valueOf(id) + "</tem:JTGKFKSPMX_ZBNM>");
				sb.append("<tem:JTGKFKSPMX_XMNR>" + content + "</tem:JTGKFKSPMX_XMNR>");
				sb.append("<tem:JTGKFKSPMX_YTSM>" + ytsm + "</tem:JTGKFKSPMX_YTSM>");
				sb.append("<tem:JTGKFKSPMX_SKDW>" + skdwid + "</tem:JTGKFKSPMX_SKDW>");
				sb.append("<tem:JTGKFKSPMX_KHH>" + skyhid + "</tem:JTGKFKSPMX_KHH>");
				sb.append("<tem:JTGKFKSPMX_KHHZH>" + sknm + "</tem:JTGKFKSPMX_KHHZH>");
				sb.append("<tem:JTGKFKSPMX_JE>" + ytjer + "</tem:JTGKFKSPMX_JE>");
				sb.append("<tem:JTGKFKSPMX_BZ>" + ytbz + "</tem:JTGKFKSPMX_BZ>");
				sb.append("<tem:JTGKFKSPMX_ZJE>" + zerhjxx + "</tem:JTGKFKSPMX_ZJE>");
				sb.append("<tem:JTGKFKSPMX_ZJEDX>" + zjjerdx + "</tem:JTGKFKSPMX_ZJEDX>");
				sb.append("<tem:JTGKFKSPMX_FKYH></tem:JTGKFKSPMX_FKYH>");
				sb.append("<tem:JTGKFKSPMX_FKYHZH></tem:JTGKFKSPMX_FKYHZH>");
				sb.append("</tem:JTGKFKSPMX>");
			}
		} else {
			sb.append("<tem:JTGKFKSPMX></tem:JTGKFKSPMX>");
		}

		sb.append("</tem:JTGKFKSPMXS>");

		// 查询付款审批表单付款银行信息表
		sb.append("<tem:JTGKFKSPFKYHS>");
		List<FukuanBankVO> bankList = this.dealDataDao.findFukuanBank(Long.valueOf(formRecordId));
		if (bankList != null && bankList.size() > 0) {
			for (FukuanBankVO fukuanBankVO : bankList) {
				sb.append("<tem:JTGKFKSPFKYH>");
				Long bankId = fukuanBankVO.getId();
				String fkyh = fukuanBankVO.getFkyh();
				String fkyhzh = fukuanBankVO.getFkyhzh();
				BigDecimal fkjer = fukuanBankVO.getFkjer();
				String fkyhid = fukuanBankVO.getFkyhid();
				String fkyhlhh = fukuanBankVO.getFkyhlhh();
				String fknm = fukuanBankVO.getFknm();
				sb.append("<tem:JTGKFKSPFKYH_NM>" + String.valueOf(bankId) + "</tem:JTGKFKSPFKYH_NM>");
				sb.append("<tem:JTGKFKSPFKYH_ZBNM>" + String.valueOf(id) + "</tem:JTGKFKSPFKYH_ZBNM>");
				sb.append("<tem:JTGKFKSPFKYH_FKYH>" + fkyh + "</tem:JTGKFKSPFKYH_FKYH>");
				sb.append("<tem:JTGKFKSPFKYH_FKYHZH>" + fkyhzh + "</tem:JTGKFKSPFKYH_FKYHZH>");
				sb.append("<tem:JTGKFKSPFKYH_FKJE>" + fkjer + "</tem:JTGKFKSPFKYH_FKJE>");
				sb.append("<tem:JTGKFKSPFKYH_YHID>" + fkyhid + "</tem:JTGKFKSPFKYH_YHID>");
				sb.append("<tem:JTGKFKSPFKYH_LHH>" + fkyhlhh + "</tem:JTGKFKSPFKYH_LHH>");
				sb.append("<tem:JTGKFKSPFKYH_FKNM>" + fknm + "</tem:JTGKFKSPFKYH_FKNM>");
				sb.append("</tem:JTGKFKSPFKYH>");
			}
		} else {
			sb.append("<tem:JTGKFKSPFKYH></tem:JTGKFKSPFKYH>");
		}
		sb.append("</tem:JTGKFKSPFKYHS>");

		attaList = dealDataDao.attachmentList(xgfj, true);
		String fjXml = getAttaXml(attaList, id);
		sb.append(fjXml);
		sb.append("</tem:record>");
		sb.append("</tem:Write>");
		sb.append("</soap:Body>");
		sb.append("</soap:Envelope>");
		return sb.toString();
	}

	// 拼接劳务费xml参数
	public String getLwfXml(String formRecordId, String sessionId, List<Attachment> attaList) {
		LaowufeiVO laowufeiVO = dealDataDao.findLaowufById(Long.valueOf(formRecordId));
		Long id = laowufeiVO.getId();
		Date writeTime = laowufeiVO.getWriteTime();
		// String sqbm=laowufeiVO.getSqbm();
		String bmCode = laowufeiVO.getBmCode();
		String unitCode = laowufeiVO.getUnitCode();
		String sqr = laowufeiVO.getSqr();
		String name = laowufeiVO.getName();
		String idcard = laowufeiVO.getIdcard();
		String zhiwu = laowufeiVO.getZhiwu();
		String skkhh = laowufeiVO.getSkkhh();
		Date times = laowufeiVO.getTimes();
		String place = laowufeiVO.getPlace();
		String keshi = laowufeiVO.getKeshi();
		String content = laowufeiVO.getContent();
		BigDecimal jkfy = laowufeiVO.getJkfy();
		String jkfydx = laowufeiVO.getJkfydx();
		String remark = laowufeiVO.getRemark();
		String fkzh = laowufeiVO.getFkzh();// 付款账号
		String skkhm = laowufeiVO.getSkkhm();
		String skyhzh = laowufeiVO.getSkyhzh();// 收款银行账号-银行的数据内码
		String yhid = laowufeiVO.getYhid();// 付款银行id

		// String fkyh=laowufeiVO.getFkyh();//付款银行
		String fkyhzh = laowufeiVO.getFkyhzh();// 付款银行账号-银行账户的数据内码
		String skyhid = laowufeiVO.getSkyhid();// 收款银行id
		/* 2023/7/23 新增编号 start */
		String lwfCode = laowufeiVO.getLwfCode();
		/* 2023/7/23 新增编号 end */

		StringBuffer sb = new StringBuffer();
		sb.append(getHeadXml(sessionId));
		// 主对象
		sb.append("<tem:record>");
		sb.append("<tem:JTGKLWF_NM>" + String.valueOf(id) + "</tem:JTGKLWF_NM>");
		sb.append("<tem:JTGKLWF_DWBH>" + unitCode + "</tem:JTGKLWF_DWBH>");// 单位编号
		String pzrq = DateUtil.format(writeTime, "yyyy-MM-dd");
		sb.append("<tem:JTGKLWF_PZRQ>" + pzrq + "</tem:JTGKLWF_PZRQ>");
		sb.append("<tem:JTGKLWF_FJS></tem:JTGKLWF_FJS>");
		sb.append("<tem:JTGKLWF_SFZF>0</tem:JTGKLWF_SFZF>");
		/* 2023/7/23 新增编号 start */
		sb.append("<tem:JTGKLWF_BY5>" + lwfCode + "</tem:JTGKLWF_BY5>");
		/* 2023/7/23 新增编号 end */
		// 从对象集合
		sb.append("<tem:JTGKLWFMXS>");
		sb.append("<tem:JTGKLWFMX>");
		sb.append("<tem:JTGKLWFMX_NM>" + String.valueOf(id) + "</tem:JTGKLWFMX_NM>");
		sb.append("<tem:JTGKLWFMX_ZBNM>" + String.valueOf(id) + "</tem:JTGKLWFMX_ZBNM>");
		sb.append("<tem:JTGKLWFMX_BMBH>" + bmCode + "</tem:JTGKLWFMX_BMBH>");
		sb.append("<tem:JTGKLWFMX_SQR>" + sqr + "</tem:JTGKLWFMX_SQR>");
		sb.append("<tem:JTGKLWFMX_ZJXM>" + name + "</tem:JTGKLWFMX_ZJXM>");
		sb.append("<tem:JTGKLWFMX_ZJSFZ>" + idcard + "</tem:JTGKLWFMX_ZJSFZ>");
		sb.append("<tem:JTGKLWFMX_ZW>" + zhiwu + "</tem:JTGKLWFMX_ZW>");
		sb.append("<tem:JTGKLWFMX_KHH>" + skyhid + "</tem:JTGKLWFMX_KHH>");
		sb.append("<tem:JTGKLWFMX_KHHZH>" + skyhzh + "</tem:JTGKLWFMX_KHHZH>");
		String sj = DateUtil.format(times, "yyyy-MM-dd");
		sb.append("<tem:JTGKLWFMX_SJ>" + sj + "</tem:JTGKLWFMX_SJ>");
		sb.append("<tem:JTGKLWFMX_DD>" + place + "</tem:JTGKLWFMX_DD>");
		sb.append("<tem:JTGKLWFMX_KS>" + keshi + "</tem:JTGKLWFMX_KS>");
		sb.append("<tem:JTGKLWFMX_NY>" + content + "</tem:JTGKLWFMX_NY>");
		sb.append("<tem:JTGKLWFMX_JKFY>" + jkfy + "</tem:JTGKLWFMX_JKFY>");
		sb.append("<tem:JTGKLWFMX_JKFYDX>" + jkfydx + "</tem:JTGKLWFMX_JKFYDX>");
		sb.append("<tem:JTGKLWFMX_BZ>" + remark + "</tem:JTGKLWFMX_BZ>");
		sb.append("<tem:JTGKLWFMX_FKZH></tem:JTGKLWFMX_FKZH>");
		sb.append("<tem:JTGKLWFMX_FKYH>" + yhid + "</tem:JTGKLWFMX_FKYH>");
		sb.append("<tem:JTGKLWFMX_FKYHZH>" + fkyhzh + "</tem:JTGKLWFMX_FKYHZH>");
		sb.append("</tem:JTGKLWFMX>");
		sb.append("</tem:JTGKLWFMXS>");
		// 从对象附件
		String fjXml = getAttaXml(attaList, id);
		sb.append(fjXml);
		sb.append("</tem:record>");
		sb.append("</tem:Write>");
		sb.append("</soap:Body>");
		sb.append("</soap:Envelope>");
		return sb.toString();
	}

	// 组装附件xml
	public String getAttaXml(List<Attachment> attaList, Long formId) {
		StringBuffer sb = new StringBuffer();
		long maxSize = 52428800;// 文件最大为50M
		sb.append("<tem:FLLIST>");
		if (attaList != null && attaList.size() > 0) {
			for (Attachment attachment : attaList) {
				if (maxSize >= attachment.getSize()) {
					sb.append("<tem:JTGKFJJL>");
					sb.append("<tem:JTGKFJJL_NM>" + attachment.getId() + "</tem:JTGKFJJL_NM>");
					sb.append("<tem:JTGKFJJL_BILLID>" + String.valueOf(formId) + "</tem:JTGKFJJL_BILLID>");
					sb.append("<tem:JTGKFJJL_FJID>" + attachment.getFileUrl() + "</tem:JTGKFJJL_FJID>");
					sb.append("<tem:JTGKFJJL_FJNAME>" + attachment.getFilename() + "</tem:JTGKFJJL_FJNAME>");
					sb.append("<tem:JTGKFJJL_FJSIZE>" + attachment.getSize() + "</tem:JTGKFJJL_FJSIZE>");
					sb.append("<tem:JTGKFJJL_CJRQ>" + DateUtil.format(attachment.getCreatedate(), "yyyy-MM-dd")
							+ "</tem:JTGKFJJL_CJRQ>");
					sb.append("</tem:JTGKFJJL>");
				}
			}
		}
		sb.append("</tem:FLLIST>");
		return sb.toString();
	}

	public String getHeadXml(String sessionId) {
		StringBuffer sb = new StringBuffer();
		sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
		// sb.append("<soap:Envelope
		// xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
		// xmlns:tem=\"http://tempuri.org/\"
		// xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
		// xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
		sb.append(
				"<soap:Envelope xmlns:tem=\"http://tempuri.org/\" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">");
		sb.append("<soap:Header>");
		sb.append("<tem:GsSession>");
		sb.append("<tem:SessionID>" + sessionId + "</tem:SessionID>");
		sb.append("</tem:GsSession>");
		sb.append("</soap:Header>");
		sb.append("<soap:Body>");
		sb.append("<tem:Write xmlns=\"http://WebXml.com.cn/\">");
		return sb.toString();
	}

	public FinancialDataPO getFinancialDataPO(String formrecordId, Long summaryId, String templateCode) {
		FinancialDataPO po = new FinancialDataPO();
		po.setIdIfNew();
		po.setSummaryId(String.valueOf(summaryId));
		po.setTemplateCode(templateCode);
		po.setFormRecordId(formrecordId);
		po.setState("1");// 默认失败，
		po.setCreateTime(new Date());
		po.setUpdateTime(new Date());
		return po;
	}

	@SuppressWarnings("deprecation")
	@ListenEvent(event = CollaborationAffairsAssignedEvent.class, mode = EventTriggerMode.afterCommit)
	public void doCollaborationAffairsAssignedEvent(CollaborationAffairsAssignedEvent event) throws BusinessException {
		logger.info("----------------------------浪潮推送事件监听");
		String fukuanCode = AppContext.getSystemProperty("gkcwplugin.fukuanCode");
		String zijinrzCode = AppContext.getSystemProperty("gkcwplugin.zijinrzCode");
		String neibuzjCode = AppContext.getSystemProperty("gkcwplugin.neibuzjCode");
		String hetongkCode = AppContext.getSystemProperty("gkcwplugin.hetongkCode");
		String chailfCode = AppContext.getSystemProperty("gkcwplugin.chailfCode");
		String fapiaorzCode = AppContext.getSystemProperty("gkcwplugin.fapiaorzCode");
		String fapiaokjCode = AppContext.getSystemProperty("gkcwplugin.fapiaokjCode");
		String huikuanCode = AppContext.getSystemProperty("gkcwplugin.huikuanCode");

		String realNodeName = AppContext.getSystemProperty("gkcwplugin.nodeName");

		// 模板编号，判断是否为相关财务表单流程
		String templateCode = null;
		try {
			templateCode = event.getTemplateCode();
		} catch (BusinessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.info("--------------------------templateCode:" + templateCode);
		// 由于每个表单可能会存在不同的流程，所以对模板编号进行截取，比如付款审批的模板编号为fkspTemCode01，配置文件只配置fkspTemCode
		if (templateCode == null || "".equals(templateCode)) {
			return;
		}
		int len = templateCode.length() - 4;
		templateCode = templateCode.substring(0, len);
		
		if (!fukuanCode.equals(templateCode) && !zijinrzCode.equals(templateCode)
				&& !neibuzjCode.equals(templateCode) && !hetongkCode.equals(templateCode)
				&& !chailfCode.equals(templateCode) && !fapiaorzCode.equals(templateCode)
				&& !fapiaokjCode.equals(templateCode) && !huikuanCode.equals(templateCode)) {
			return;
		}

		String formRecordId = event.getCurrentAffair().getFormRecordid().toString();
		logger.info("---------------------formrecordid:" + formRecordId);
		
		Map<String, Object> data = new HashMap<String, Object>();
		List<PayItemPO> payItemPOList = new ArrayList<PayItemPO>();

		// url地址拼接
		String url = "/seeyon/collaboration/collaboration.do?method=summary&openFrom=listSent&affairId="
				+ event.getCurrentAffair().getId().toString();
		String urlCode = null;

		Long memberId = event.getCurrentAffair().getMemberId();
		
		V3xOrgMember member = orgManager.getMemberById(memberId);

		String ticket = Base64.encode(member.getCode());
		logger.info("--------------------------ticket:" + ticket);

		try {
			url = "http://114.218.158.106:8801/seeyon/login/sso?from=sample&ticket=" + ticket + "&tourl="
					+ URLEncoder.encode(url, "UTF-8");
			urlCode = URLEncoder.encode(url, "UTF-8");
			logger.info("--------------------------url:" + url);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		
		String nodeName = event.getCurrentAffair().getNodeName();

		if (!realNodeName.equals(nodeName)) {
			// -----付款审批表流程模板编号
			if (fukuanCode.equals(templateCode)) {
				List<FukuanSonPO> sonList = dealDataDao.findFukuanSonPO(Long.valueOf(formRecordId));
				
				for (FukuanSonPO row : sonList) {
					if (row.getYhhd() == null || "".equals(row.getYhhd().toString())) {
						return;
					}
				}
				
				FukuanPO fukuanPO = dealDataDao.findFukuanPOById(Long.valueOf(formRecordId));
				List<FukuanPJPO> pjList = dealDataDao.findFukuanPJPO(Long.valueOf(formRecordId));
				String cnmx = null;
				
				if (sonList.size() > 0) {
					cnmx = sonList.get(0).getCnmx();
				}
				
//				List<FukuanBankPO> bankList = dealDataDao.findFukuanBankPO(Long.valueOf(formRecordId));
				
				Connection conn = BaseConnection.getConnection();
				PreparedStatement ps = null;
				int rs = 0;

				try {
					logger.info("--------------------------主表插入开始");
					String zbSql = "INSERT INTO OAZJB_ZB (OAZJB_ZB_ID,OAZJB_ZB_BDLX,OAZJB_ZB_HSDW,"
							+ "OAZJB_ZB_BXBM,OAZJB_ZB_SQRQ,OAZJB_ZB_FKSY,OAZJB_ZB_SFZX,OAZJB_ZB_HZJE,"
							+ "OAZJB_ZB_SQR,OAZJB_ZB_FKRQ,OAZJB_ZB_FKBM,OAZJB_ZB_FKDW,OAZJB_ZB_LSBH,OAZJB_ZB_LCDZ,OAZJB_ZB_BY1)"
							+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

					ps = conn.prepareStatement(zbSql);
					ps.setLong(1, fukuanPO.getId());
					ps.setString(2, "1");
					logger.info("--------------------------getHsdw:" + fukuanPO.getHsdw());
					ps.setString(3, fukuanPO.getHsdw());
					logger.info("--------------------------getBxbm:" + fukuanPO.getBxbm());
					ps.setString(4, fukuanPO.getBxbm());
					logger.info("--------------------------getSqrq:" + fukuanPO.getSqrq());
					if (fukuanPO.getSqrq() != null) {
						java.sql.Date sqrq = new java.sql.Date(fukuanPO.getSqrq().getTime());
						ps.setDate(5, sqrq);
					} else {
						ps.setDate(5, null);
					}
					logger.info("--------------------------getFksy:" + fukuanPO.getFksy());
					ps.setString(6, fukuanPO.getFksy());
					logger.info("--------------------------getSfzx:" + fukuanPO.getSfzx());
					ps.setBigDecimal(7, fukuanPO.getSfzx());
					logger.info("--------------------------getHzje:" + fukuanPO.getHzje());
					ps.setBigDecimal(8, fukuanPO.getHzje());
					logger.info("--------------------------getSqr:" + fukuanPO.getSqr());
					ps.setString(9, fukuanPO.getSqr());
					logger.info("--------------------------getFkrq:" + fukuanPO.getFkrq());
					if (fukuanPO.getFkrq() != null) {
						java.sql.Date fkrq = new java.sql.Date(fukuanPO.getFkrq().getTime());
						ps.setDate(10, fkrq);
					} else {
						ps.setDate(10, null);
					}
					logger.info("--------------------------getFkbm:" + fukuanPO.getFkbm());
					ps.setString(11, fukuanPO.getFkbm());
					logger.info("--------------------------getFkdw:" + fukuanPO.getFkdw());
					ps.setString(12, fukuanPO.getFkdw());
					logger.info("--------------------------getLsbh:" + fukuanPO.getLsbh());
					ps.setString(13, fukuanPO.getLsbh());
					ps.setString(14, url);
					logger.info("--------------------------getXmbh:" + fukuanPO.getXmbh());
					ps.setString(15, fukuanPO.getXmbh());
					
					rs = ps.executeUpdate();
					
					if (rs < 0) {
						return;
					}
					logger.info("--------------------------主表插入结束");
					logger.info("--------------------------票据表插入开始");
					
					for (FukuanPJPO row : pjList) {
//						row.setCnmx(sonList.get(0).getCnmx());
						
						String pjSql = "INSERT INTO OAZJB_PJXX (OAZJB_PJXX_ID,OAZJB_PJXX_MXID,OAZJB_PJXX_FYRX,OAZJB_PJXX_FYBM,"
								+ "OAZJB_PJXX_RYR,OAZJB_PJXX_FYXM,OAZJB_PJXX_FYLX,OAZJB_PJXX_FLXMBH,OAZJB_PJXX_BXBZ,"
								+ "OAZJB_PJXX_PJRX,OAZJB_PJXX_KPMC,OAZJB_PJXX_XFSBM,OAZJB_PJXX_KPRQ,OAZJB_PJXX_JE,"
								+ "OAZJB_PJXX_SE,OAZJB_PJXX_SL,OAZJB_PJXX_KDJE,OAZJB_PJXX_HSJE,OAZJB_PJXX_FPDM,OAZJB_PJXX_FPBH,"
								+ "OAZJB_PJXX_FPXM,OAZJB_PJXX_XFMC,OAZJB_PJXX_SKYH,OAZJB_PJXX_SKZH,OAZJB_PJXX_BY1,OAZJB_PJXX_BY2)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(pjSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						logger.info("--------------------------getFyrx:" + row.getFyrx());
						ps.setString(3, row.getFyrx());
						logger.info("--------------------------getFybm:" + row.getFybm());
						ps.setString(4, row.getFybm());
						logger.info("--------------------------getRyr:" + row.getRyr());
						ps.setString(5, row.getRyr());
						logger.info("--------------------------getFyxm:" + row.getFyxm());
						ps.setString(6, row.getFyxm());
						logger.info("--------------------------getFylx:" + row.getFylx());
						ps.setString(7, row.getFylx());
						logger.info("--------------------------getFlxmbh:" + row.getFlxmbh());
						ps.setString(8, row.getFlxmbh());
						logger.info("--------------------------getBxbz:" + row.getBxbz());
						ps.setString(9, row.getBxbz());
						logger.info("--------------------------getPjrx:" + row.getPjrx());
						ps.setString(10, row.getPjrx());
						logger.info("--------------------------getKpmc:" + row.getKpmc());
						ps.setString(11, row.getKpmc());
						logger.info("--------------------------getXfsbm:" + row.getXfsbm());
						ps.setString(12, row.getXfsbm());
						if (row.getKprq() != null) {
							logger.info("--------------------------getKprq:" + row.getKprq().getTime());
							java.sql.Date kprq = new java.sql.Date(row.getKprq().getTime());
							ps.setDate(13, kprq);
						} else {
							ps.setDate(13, null);
						}
						logger.info("--------------------------getJe:" + row.getJe());
						ps.setBigDecimal(14, row.getJe());
						logger.info("--------------------------getSe:" + row.getSe());
						logger.info("--------------------------getSl:" + row.getSl());
						if (row.getSl() != null) {
							ps.setBigDecimal(15, row.getSe());
							if (row.getSl().contains("%")) {
								int index = row.getSl().indexOf("%");
								String sl = row.getSl().substring(0, index).trim();
								BigDecimal divide = new BigDecimal(sl).divide(new BigDecimal(100));
								
								ps.setString(16, divide.toString());
							} else {
								ps.setString(16, row.getSl());
							}
						} else {
							ps.setBigDecimal(15, BigDecimal.ZERO);
							ps.setString(16, "0");
						}
						logger.info("--------------------------getKdje:" + row.getKdje());
						ps.setBigDecimal(17, row.getKdje());
						logger.info("--------------------------getHsje:" + row.getHsje());
						ps.setBigDecimal(18, row.getHsje());
						logger.info("--------------------------getFpdm:" + row.getFpdm());
						ps.setString(19, row.getFpdm());
						logger.info("--------------------------getFpbh:" + row.getFpbh());
						ps.setString(20, row.getFpbh());
						logger.info("--------------------------getFpxm:" + row.getFpxm());
						ps.setString(21, row.getFpxm());
						logger.info("--------------------------getXfmc:" + row.getXfmc());
						ps.setString(22, row.getXfmc());
						logger.info("--------------------------getSkyh:" + row.getSkyh());
						ps.setString(23, row.getSkyh());
						logger.info("--------------------------getSkzh:" + row.getSkzh());
						ps.setString(24, row.getSkzh());
						logger.info("--------------------------getZjyt:" + row.getZjyt());
						ps.setString(25, row.getZjyt());
						
						ps.setString(26, cnmx);
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------票据表插入结束");
					logger.info("--------------------------出纳表插入开始");
					for (FukuanSonPO row : sonList) {
						String cnSql = "INSERT INTO OAZJB_CNXX (OAZJB_CNXX_ID,OAZJB_CNXX_MXID,OAZJB_CNXX_XH,OAZJB_CNXX_ZFFS,"
								+ "OAZJB_CNXX_SKYH,OAZJB_CNXX_SKZH,OAZJB_CNXX_SKR,OAZJB_CNXX_ZFJE,OAZJB_CNXX_ZFSM,"
								+ "OAZJB_CNXX_CNFKYH,OAZJB_CNXX_CNFKZH,OAZJB_CNXX_BY1)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(cnSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						logger.info("--------------------------getXh:" + row.getXh());
						ps.setBigDecimal(3, row.getXh());
						logger.info("--------------------------getZffs:" + row.getZffs());
						ps.setString(4, row.getZffs());
						logger.info("--------------------------getSkyh:" + row.getSkyh());
						ps.setString(5, row.getSkyh());
						logger.info("--------------------------getSkzh:" + row.getSkzh());
						ps.setString(6, row.getSkzh());
						logger.info("--------------------------getSkr:" + row.getSkr());
						ps.setString(7, row.getSkr());
						logger.info("--------------------------getZfje:" + row.getZfje());
						ps.setBigDecimal(8, row.getZfje());
						logger.info("--------------------------getZfsm:" + row.getZfsm());
						ps.setString(9, row.getZfsm());
						logger.info("--------------------------getCnfkyh:" + row.getCnfkyh());
						ps.setString(10, row.getCnfkyh());
						logger.info("--------------------------getCnfkzh:" + row.getCnfkzh());
						ps.setString(11, row.getCnfkzh());
						logger.info("--------------------------getCnmx:" + row.getCnmx());
						ps.setString(12, row.getCnmx());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------出纳表插入结束");
//					logger.info("--------------------------回单表插入开始");
//					for (FukuanBankPO row : bankList) {
//						String htSql = "INSERT INTO OAZJB_HTXX (OAZJB_HTXX_ID,OAZJB_HTXX_MXID,OAZJB_HTXX_XH,"
//								+ "OAZJB_HTXX_FKZH,OAZJB_HTXX_YHKD,OAZJB_HTXX_PZH)"
//								+ "VALUES (?,?,?,?,?,?)";
//
//						ps = conn.prepareStatement(htSql);
//						ps.setLong(1, row.getFormmainId());
//						ps.setLong(2, row.getId());
//						ps.setBigDecimal(3, row.getXh());
//						ps.setString(4, row.getFkzh());
//						ps.setString(5, row.getYhkd());
//						ps.setString(6, row.getPzh());
//						
//						rs = ps.executeUpdate();
//						
//						if (rs < 0) {
//							return;
//						}
//					}
//					logger.info("--------------------------回单表插入结束");

				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
						ps.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}

				return;
			} else if (zijinrzCode.equals(templateCode)) {// ---------资金入账申请表
				List<ZiJinRZSonPO> sonList = dealDataDao.findZiJinRZSonPO(Long.valueOf(formRecordId));
				
				for (ZiJinRZSonPO row : sonList) {
					if (row.getYhhd() == null || "".equals(row.getYhhd().toString())) {
						return;
					}
				}
				
				ZiJinRZPO ZiJinRZPO = dealDataDao.findZiJinRZPOById(Long.valueOf(formRecordId));
				
//				List<ZiJinRZBankPO> bankList = dealDataDao.findZiJinRZBankPO(Long.valueOf(formRecordId));

				Connection conn = BaseConnection.getConnection();
				PreparedStatement ps = null;
				int rs = 0;

				try {
					logger.info("--------------------------主表插入开始");
					String zbSql = "INSERT INTO OAZJB_ZB (OAZJB_ZB_ID,OAZJB_ZB_BDLX,OAZJB_ZB_HSDW,"
							+ "OAZJB_ZB_BXBM,OAZJB_ZB_SQRQ,OAZJB_ZB_FKSY,OAZJB_ZB_SFZX,OAZJB_ZB_HZJE,"
							+ "OAZJB_ZB_SQR,OAZJB_ZB_FKRQ,OAZJB_ZB_FKBM,OAZJB_ZB_FKDW,OAZJB_ZB_LSBH,OAZJB_ZB_LCDZ)"
							+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

					ps = conn.prepareStatement(zbSql);
					ps.setLong(1, ZiJinRZPO.getId());
					ps.setString(2, "6");
					ps.setString(3, ZiJinRZPO.getHsdw());
					ps.setString(4, ZiJinRZPO.getBxbm());
					if (ZiJinRZPO.getSqrq() != null) {
						java.sql.Date sqrq = new java.sql.Date(ZiJinRZPO.getSqrq().getTime());
						ps.setDate(5, sqrq);
					} else {
						ps.setDate(5, null);
					}
					ps.setString(6, ZiJinRZPO.getFksy());
					ps.setBigDecimal(7, ZiJinRZPO.getSfzx());
					ps.setBigDecimal(8, ZiJinRZPO.getHzje());
					ps.setString(9, ZiJinRZPO.getSqr());
					if (ZiJinRZPO.getFkrq() != null) {
						java.sql.Date fkrq = new java.sql.Date(ZiJinRZPO.getFkrq().getTime());
						ps.setDate(10, fkrq);
					} else {
						ps.setDate(10, null);
					}
					ps.setString(11, ZiJinRZPO.getFkbm());
					ps.setString(12, ZiJinRZPO.getFkdw());
					ps.setString(13, ZiJinRZPO.getLsbh());
					ps.setString(14, url);
					
					rs = ps.executeUpdate();
					
					if (rs < 0) {
						return;
					}
					logger.info("--------------------------主表插入结束");
					logger.info("--------------------------出纳表插入开始");
					for (ZiJinRZSonPO row : sonList) {
						String cnSql = "INSERT INTO OAZJB_CNXX (OAZJB_CNXX_ID,OAZJB_CNXX_MXID,OAZJB_CNXX_XH,OAZJB_CNXX_ZFFS,"
								+ "OAZJB_CNXX_SKYH,OAZJB_CNXX_SKZH,OAZJB_CNXX_SKR,OAZJB_CNXX_ZFJE,OAZJB_CNXX_ZFSM,"
								+ "OAZJB_CNXX_CNFKYH,OAZJB_CNXX_CNFKZH,OAZJB_CNXX_BY1,OAZJB_CNXX_BY2,OAZJB_CNXX_BY3)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(cnSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						ps.setBigDecimal(3, row.getXh());
						ps.setString(4, row.getZffs());
						ps.setString(5, row.getSkyh());
						ps.setString(6, row.getSkzh());
						ps.setString(7, row.getSkr());
						ps.setBigDecimal(8, row.getZfje());
						ps.setString(9, row.getZfsm());
						ps.setString(10, row.getCnfkyh());
						ps.setString(11, row.getCnfkzh());
						ps.setString(12, row.getKpmc());
						ps.setString(13, row.getZjyt());
						ps.setString(14, row.getYh());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------出纳表插入结束");
//					logger.info("--------------------------回单表插入开始");
//					for (ZiJinRZBankPO row : bankList) {
//						String htSql = "INSERT INTO OAZJB_HTXX (OAZJB_HTXX_ID,OAZJB_HTXX_MXID,OAZJB_HTXX_XH,"
//								+ "OAZJB_HTXX_FKZH,OAZJB_HTXX_YHKD,OAZJB_HTXX_PZH)"
//								+ "VALUES (?,?,?,?,?,?)";
//
//						ps = conn.prepareStatement(htSql);
//						ps.setLong(1, row.getFormmainId());
//						ps.setLong(2, row.getId());
//						ps.setBigDecimal(3, row.getXh());
//						ps.setString(4, row.getFkzh());
//						ps.setString(5, row.getYhkd());
//						ps.setString(6, row.getPzh());
//						
//						rs = ps.executeUpdate();
//						
//						if (rs < 0) {
//							return;
//						}
//					}
//					logger.info("--------------------------回单表插入结束");

				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
						ps.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				
				return;
			} else if (neibuzjCode.equals(templateCode)) {// --------内部资金拨付单
				List<NeibuZjSonPO> sonList = dealDataDao.findNeibuZjSonPO(Long.valueOf(formRecordId));
				
				for (NeibuZjSonPO row : sonList) {
					if (row.getYhhd() == null || "".equals(row.getYhhd().toString())) {
						return;
					}
				}
				
				NeibuZjPO neibuZjPO = dealDataDao.findNeibuZjPOById(Long.valueOf(formRecordId));
//				List<NeibuZjPJPO> pjList = dealDataDao.findNeibuZjPJPO(Long.valueOf(formRecordId));
//				List<NeibuZjBankPO> bankList = dealDataDao.findNeibuZjBankPO(Long.valueOf(formRecordId));
				
				Connection conn = BaseConnection.getConnection();
				PreparedStatement ps = null;
				int rs = 0;

				try {
					logger.info("--------------------------主表插入开始");
					String zbSql = "INSERT INTO OAZJB_ZB (OAZJB_ZB_ID,OAZJB_ZB_BDLX,OAZJB_ZB_HSDW,"
							+ "OAZJB_ZB_BXBM,OAZJB_ZB_SQRQ,OAZJB_ZB_FKSY,OAZJB_ZB_SFZX,OAZJB_ZB_HZJE,"
							+ "OAZJB_ZB_SQR,OAZJB_ZB_FKRQ,OAZJB_ZB_FKBM,OAZJB_ZB_FKDW,OAZJB_ZB_LSBH,OAZJB_ZB_LCDZ)"
							+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

					ps = conn.prepareStatement(zbSql);
					ps.setLong(1, neibuZjPO.getId());
					ps.setString(2, "8");
					ps.setString(3, neibuZjPO.getHsdw());
					ps.setString(4, neibuZjPO.getBxbm());
					if (neibuZjPO.getSqrq() != null) {
						java.sql.Date sqrq = new java.sql.Date(neibuZjPO.getSqrq().getTime());
						ps.setDate(5, sqrq);
					} else {
						ps.setDate(5, null);
					}
					ps.setString(6, neibuZjPO.getFksy());
					ps.setBigDecimal(7, neibuZjPO.getSfzx());
					ps.setBigDecimal(8, neibuZjPO.getHzje());
					ps.setString(9, neibuZjPO.getSqr());
					if (neibuZjPO.getFkrq() != null) {
						java.sql.Date fkrq = new java.sql.Date(neibuZjPO.getFkrq().getTime());
						ps.setDate(10, fkrq);
					} else {
						ps.setDate(10, null);
					}
					ps.setString(11, neibuZjPO.getFkbm());
					ps.setString(12, neibuZjPO.getFkdw());
					ps.setString(13, neibuZjPO.getLsbh());
					ps.setString(14, url);
					
					rs = ps.executeUpdate();
					
					if (rs < 0) {
						return;
					}
					logger.info("--------------------------主表插入结束");
//					logger.info("--------------------------票据表插入开始");
//					for (NeibuZjPJPO row : pjList) {
//						String pjSql = "INSERT INTO OAZJB_PJXX (OAZJB_PJXX_ID,OAZJB_PJXX_MXID,OAZJB_PJXX_FYRX,OAZJB_PJXX_FYBM,"
//								+ "OAZJB_PJXX_RYR,OAZJB_PJXX_FYXM,OAZJB_PJXX_FYLX,OAZJB_PJXX_FLXMBH,OAZJB_PJXX_BXBZ,"
//								+ "OAZJB_PJXX_PJRX,OAZJB_PJXX_KPMC,OAZJB_PJXX_XFSBM,OAZJB_PJXX_KPRQ,OAZJB_PJXX_JE,"
//								+ "OAZJB_PJXX_SE,OAZJB_PJXX_SL,OAZJB_PJXX_KDJE,OAZJB_PJXX_HSJE,OAZJB_PJXX_FPDM,OAZJB_PJXX_FPBH)"
//								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
//
//						ps = conn.prepareStatement(pjSql);
//						ps.setLong(1, row.getFormmainId());
//						ps.setLong(2, row.getId());
//						ps.setString(3, row.getFyrx());
//						ps.setString(4, row.getFybm());
//						ps.setString(5, row.getRyr());
//						ps.setString(6, row.getFyxm());
//						ps.setString(7, row.getFylx());
//						ps.setString(8, row.getFlxmbh());
//						ps.setString(9, row.getBxbz());
//						ps.setString(10, row.getPjrx());
//						ps.setString(11, row.getKpmc());
//						ps.setString(12, row.getXfsbm());
//						java.sql.Date kprq = new java.sql.Date(row.getKprq().getTime());
//						ps.setDate(13, kprq);
//						ps.setBigDecimal(14, row.getJe());
//						if (row.getSl() != null) {
//							ps.setBigDecimal(15, row.getSe());
//							if (row.getSl().contains("%")) {
//								int index = row.getSl().indexOf("%");
//								String sl = row.getSl().substring(0, index).trim();
//								BigDecimal divide = new BigDecimal(sl).divide(new BigDecimal(100));
//								
//								ps.setString(16, divide.toString());
//							} else {
//								ps.setString(16, row.getSl());
//							}
//						} else {
//							ps.setBigDecimal(15, BigDecimal.ZERO);
//							ps.setString(16, "0");
//						}
//						
//						ps.setBigDecimal(17, row.getKdje());
//						ps.setBigDecimal(18, row.getHsje());
//						ps.setString(19, row.getFpdm());
//						ps.setString(20, row.getFpbh());
//						
//						rs = ps.executeUpdate();
//						
//						if (rs < 0) {
//							return;
//						}
//					}
//					logger.info("--------------------------票据表插入结束");
					logger.info("--------------------------出纳表插入开始");
					for (NeibuZjSonPO row : sonList) {
						String cnSql = "INSERT INTO OAZJB_CNXX (OAZJB_CNXX_ID,OAZJB_CNXX_MXID,OAZJB_CNXX_XH,OAZJB_CNXX_ZFFS,"
								+ "OAZJB_CNXX_SKYH,OAZJB_CNXX_SKZH,OAZJB_CNXX_SKR,OAZJB_CNXX_ZFJE,OAZJB_CNXX_ZFSM,"
								+ "OAZJB_CNXX_CNFKYH,OAZJB_CNXX_CNFKZH,OAZJB_CNXX_BY1,OAZJB_CNXX_BY2,OAZJB_CNXX_BY3,OAZJB_CNXX_ZY)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(cnSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						ps.setBigDecimal(3, row.getXh());
						ps.setString(4, row.getZffs());
						ps.setString(5, row.getSkyh());
						ps.setString(6, row.getSkzh());
						ps.setString(7, row.getSkr());
						ps.setBigDecimal(8, row.getZfje());
						ps.setString(9, row.getZfsm());
						ps.setString(10, row.getCnfkyh());
						ps.setString(11, row.getCnfkzh());
						ps.setString(12, row.getKpmc());
						ps.setString(13, row.getZjyt());
						ps.setString(14, row.getYh());
						ps.setString(15, row.getZhaiyao());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------出纳表插入结束");
//					logger.info("--------------------------回单表插入开始");
//					for (NeibuZjBankPO row : bankList) {
//						String htSql = "INSERT INTO OAZJB_HTXX (OAZJB_HTXX_ID,OAZJB_HTXX_MXID,OAZJB_HTXX_XH,"
//								+ "OAZJB_HTXX_FKZH,OAZJB_HTXX_YHKD,OAZJB_HTXX_PZH)"
//								+ "VALUES (?,?,?,?,?,?)";
//
//						ps = conn.prepareStatement(htSql);
//						ps.setLong(1, row.getFormmainId());
//						ps.setLong(2, row.getId());
//						ps.setBigDecimal(3, row.getXh());
//						ps.setString(4, row.getFkzh());
//						ps.setString(5, row.getYhkd());
//						ps.setString(6, row.getPzh());
//						
//						rs = ps.executeUpdate();
//						
//						if (rs < 0) {
//							return;
//						}
//					}
//					logger.info("--------------------------回单表插入结束");

				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
						ps.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}

				return;
			} else if (hetongkCode.equals(templateCode)) {// --------合同款拨付审批单
				List<HetongSonPO> sonList = dealDataDao.findHetongSonPO(Long.valueOf(formRecordId));
				
				for (HetongSonPO row : sonList) {
					if (row.getYhhd() == null || "".equals(row.getYhhd().toString())) {
						return;
					}
				}
				
				HetongPO hetongPO = dealDataDao.findHetongPOById(Long.valueOf(formRecordId));
				List<HetongPJPO> pjList = dealDataDao.findHetongPJPO(Long.valueOf(formRecordId));
				
//				List<HetongBankPO> bankList = dealDataDao.findHetongBankPO(Long.valueOf(formRecordId));
				
				Connection conn = BaseConnection.getConnection();
				PreparedStatement ps = null;
				int rs = 0;

				try {
					logger.info("--------------------------主表插入开始");
					String zbSql = "INSERT INTO OAZJB_ZB (OAZJB_ZB_ID,OAZJB_ZB_BDLX,OAZJB_ZB_HSDW,"
							+ "OAZJB_ZB_BXBM,OAZJB_ZB_SQRQ,OAZJB_ZB_FKSY,OAZJB_ZB_SFZX,OAZJB_ZB_HZJE,"
							+ "OAZJB_ZB_SQR,OAZJB_ZB_FKRQ,OAZJB_ZB_FKBM,OAZJB_ZB_FKDW,OAZJB_ZB_LSBH,"
							+ "OAZJB_ZB_LCDZ,OAZJB_ZB_BY1)"
							+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

					ps = conn.prepareStatement(zbSql);
					ps.setLong(1, hetongPO.getId());
					ps.setString(2, "3");
					ps.setString(3, hetongPO.getHsdw());
					ps.setString(4, hetongPO.getBxbm());
					if (hetongPO.getSqrq() != null) {
						java.sql.Date sqrq = new java.sql.Date(hetongPO.getSqrq().getTime());
						ps.setDate(5, sqrq);
					} else {
						ps.setDate(5, null);
					}
					ps.setString(6, hetongPO.getFksy());
					ps.setBigDecimal(7, hetongPO.getSfzx());
					ps.setBigDecimal(8, hetongPO.getHzje());
					ps.setString(9, hetongPO.getSqr());
					if (hetongPO.getFkrq() != null) {
						java.sql.Date fkrq = new java.sql.Date(hetongPO.getFkrq().getTime());
						ps.setDate(10, fkrq);
					} else {
						ps.setDate(10, null);
					}
					ps.setString(11, hetongPO.getFkbm());
					ps.setString(12, hetongPO.getFkdw());
					ps.setString(13, hetongPO.getLsbh());
					ps.setString(14, url);
					ps.setString(15, hetongPO.getXmbh());
					
					rs = ps.executeUpdate();
					
					if (rs < 0) {
						return;
					}
					logger.info("--------------------------主表插入结束");
					logger.info("--------------------------票据表插入开始");
					for (HetongPJPO row : pjList) {
						String pjSql = "INSERT INTO OAZJB_PJXX (OAZJB_PJXX_ID,OAZJB_PJXX_MXID,OAZJB_PJXX_FYRX,OAZJB_PJXX_FYBM,"
								+ "OAZJB_PJXX_RYR,OAZJB_PJXX_FYXM,OAZJB_PJXX_FYLX,OAZJB_PJXX_FLXMBH,OAZJB_PJXX_BXBZ,"
								+ "OAZJB_PJXX_PJRX,OAZJB_PJXX_KPMC,OAZJB_PJXX_XFSBM,OAZJB_PJXX_KPRQ,OAZJB_PJXX_JE,"
								+ "OAZJB_PJXX_SE,OAZJB_PJXX_SL,OAZJB_PJXX_KDJE,OAZJB_PJXX_HSJE,OAZJB_PJXX_FPDM,OAZJB_PJXX_FPBH,OAZJB_PJXX_BY1)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(pjSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						ps.setString(3, row.getFyrx());
						ps.setString(4, row.getFybm());
						ps.setString(5, row.getRyr());
						ps.setString(6, row.getFyxm());
						ps.setString(7, row.getFylx());
						ps.setString(8, row.getFlxmbh());
						ps.setString(9, row.getBxbz());
						ps.setString(10, row.getPjrx());
						ps.setString(11, row.getKpmc());
						ps.setString(12, row.getXfsbm());
						if (row.getKprq() != null) {
							java.sql.Date kprq = new java.sql.Date(row.getKprq().getTime());
							ps.setDate(13, kprq);
						} else {
							ps.setDate(13, null);
						}
						ps.setBigDecimal(14, row.getJe());
						if (row.getSl() != null) {
							ps.setBigDecimal(15, row.getSe());
							if (row.getSl().contains("%")) {
								int index = row.getSl().indexOf("%");
								String sl = row.getSl().substring(0, index).trim();
								BigDecimal divide = new BigDecimal(sl).divide(new BigDecimal(100));
								
								ps.setString(16, divide.toString());
							} else {
								ps.setString(16, row.getSl());
							}
						} else {
							ps.setBigDecimal(15, BigDecimal.ZERO);
							ps.setString(16, "0");
						}
						
						ps.setBigDecimal(17, row.getKdje());
						ps.setBigDecimal(18, row.getHsje());
						ps.setString(19, row.getFpdm());
						ps.setString(20, row.getFpbh());
						ps.setString(21, row.getZjyt());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------票据表插入结束");
					logger.info("--------------------------出纳表插入开始");
					for (HetongSonPO row : sonList) {
						String cnSql = "INSERT INTO OAZJB_CNXX (OAZJB_CNXX_ID,OAZJB_CNXX_MXID,OAZJB_CNXX_XH,OAZJB_CNXX_ZFFS,"
								+ "OAZJB_CNXX_SKYH,OAZJB_CNXX_SKZH,OAZJB_CNXX_SKR,OAZJB_CNXX_ZFJE,OAZJB_CNXX_ZFSM,"
								+ "OAZJB_CNXX_CNFKYH,OAZJB_CNXX_CNFKZH)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(cnSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						ps.setBigDecimal(3, row.getXh());
						ps.setString(4, row.getZffs());
						ps.setString(5, row.getSkyh());
						ps.setString(6, row.getSkzh());
						ps.setString(7, row.getSkr());
						ps.setBigDecimal(8, row.getZfje());
						ps.setString(9, row.getZfsm());
						ps.setString(10, row.getCnfkyh());
						ps.setString(11, row.getCnfkzh());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------出纳表插入结束");
//					logger.info("--------------------------回单表插入开始");
//					for (HetongBankPO row : bankList) {
//						String htSql = "INSERT INTO OAZJB_HTXX (OAZJB_HTXX_ID,OAZJB_HTXX_MXID,OAZJB_HTXX_XH,"
//								+ "OAZJB_HTXX_FKZH,OAZJB_HTXX_YHKD,OAZJB_HTXX_PZH)"
//								+ "VALUES (?,?,?,?,?,?)";
//
//						ps = conn.prepareStatement(htSql);
//						ps.setLong(1, row.getFormmainId());
//						ps.setLong(2, row.getId());
//						ps.setBigDecimal(3, row.getXh());
//						ps.setString(4, row.getFkzh());
//						ps.setString(5, row.getYhkd());
//						ps.setString(6, row.getPzh());
//						
//						rs = ps.executeUpdate();
//						
//						if (rs < 0) {
//							return;
//						}
//					}
//					logger.info("--------------------------回单表插入结束");

				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
						ps.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				
				return;
			} else if (chailfCode.equals(templateCode)) {// -------差旅费报销单
				List<ChailfSonPO> sonList = dealDataDao.findChailfSonPO(Long.valueOf(formRecordId));
				
				for (ChailfSonPO row : sonList) {
					if (row.getYhhd() == null || "".equals(row.getYhhd().toString())) {
						return;
					}
				}
				
				ChailfPO chailfPO = dealDataDao.findChailfPOById(Long.valueOf(formRecordId));
				List<ChailfPJPO> pjList = dealDataDao.findChailfPJPO(Long.valueOf(formRecordId));
				
//				List<ChailfBankPO> bankList = dealDataDao.findChailfBankPO(Long.valueOf(formRecordId));
				
				Connection conn = BaseConnection.getConnection();
				PreparedStatement ps = null;
				int rs = 0;

				try {
					logger.info("--------------------------主表插入开始");
					String zbSql = "INSERT INTO OAZJB_ZB (OAZJB_ZB_ID,OAZJB_ZB_BDLX,OAZJB_ZB_HSDW,"
							+ "OAZJB_ZB_BXBM,OAZJB_ZB_SQRQ,OAZJB_ZB_FKSY,OAZJB_ZB_SFZX,OAZJB_ZB_HZJE,"
							+ "OAZJB_ZB_SQR,OAZJB_ZB_FKRQ,OAZJB_ZB_FKBM,OAZJB_ZB_FKDW,OAZJB_ZB_LSBH,OAZJB_ZB_LCDZ,OAZJB_ZB_BY1)"
							+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

					ps = conn.prepareStatement(zbSql);
					ps.setLong(1, chailfPO.getId());
					ps.setString(2, "2");
					ps.setString(3, chailfPO.getHsdw());
					ps.setString(4, chailfPO.getBxbm());
					if (chailfPO.getSqrq() != null) {
						java.sql.Date sqrq = new java.sql.Date(chailfPO.getSqrq().getTime());
						ps.setDate(5, sqrq);
					} else {
						ps.setDate(5, null);
					}
					ps.setString(6, chailfPO.getFksy());
					ps.setBigDecimal(7, chailfPO.getSfzx());
					ps.setBigDecimal(8, chailfPO.getHzje());
					ps.setString(9, chailfPO.getSqr());
					if (chailfPO.getFkrq() != null) {
						java.sql.Date fkrq = new java.sql.Date(chailfPO.getFkrq().getTime());
						ps.setDate(10, fkrq);
					} else {
						ps.setDate(10, null);
					}
					ps.setString(11, chailfPO.getFkbm());
					ps.setString(12, chailfPO.getFkdw());
					ps.setString(13, chailfPO.getLsbh());
					ps.setString(14, url);
					ps.setString(15, chailfPO.getXmbh());
					
					rs = ps.executeUpdate();
					
					if (rs < 0) {
						return;
					}
					logger.info("--------------------------主表插入结束");
					logger.info("--------------------------票据表插入开始");
					for (ChailfPJPO row : pjList) {
						String pjSql = "INSERT INTO OAZJB_PJXX (OAZJB_PJXX_ID,OAZJB_PJXX_MXID,OAZJB_PJXX_FYRX,OAZJB_PJXX_FYBM,"
								+ "OAZJB_PJXX_RYR,OAZJB_PJXX_FYXM,OAZJB_PJXX_FYLX,OAZJB_PJXX_FLXMBH,OAZJB_PJXX_BXBZ,"
								+ "OAZJB_PJXX_PJRX,OAZJB_PJXX_KPMC,OAZJB_PJXX_XFSBM,OAZJB_PJXX_KPRQ,OAZJB_PJXX_JE,"
								+ "OAZJB_PJXX_SE,OAZJB_PJXX_SL,OAZJB_PJXX_KDJE,OAZJB_PJXX_HSJE,OAZJB_PJXX_FPDM,OAZJB_PJXX_FPBH)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(pjSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						ps.setString(3, row.getFyrx());
						ps.setString(4, row.getFybm());
						ps.setString(5, row.getRyr());
						ps.setString(6, row.getFyxm());
						ps.setString(7, row.getFylx());
						ps.setString(8, row.getFlxmbh());
						ps.setString(9, row.getBxbz());
						ps.setString(10, row.getPjrx());
						ps.setString(11, row.getKpmc());
						ps.setString(12, row.getXfsbm());
						if (row.getKprq() != null) {
							java.sql.Date kprq = new java.sql.Date(row.getKprq().getTime());
							ps.setDate(13, kprq);
						} else {
							ps.setDate(13, null);
						}
						ps.setBigDecimal(14, row.getJe());
						if (row.getSl() != null) {
							ps.setBigDecimal(15, row.getSe());
							if (row.getSl().contains("%")) {
								int index = row.getSl().indexOf("%");
								String sl = row.getSl().substring(0, index).trim();
								BigDecimal divide = new BigDecimal(sl).divide(new BigDecimal(100));
								
								ps.setString(16, divide.toString());
							} else {
								ps.setString(16, row.getSl());
							}
						} else {
							ps.setBigDecimal(15, BigDecimal.ZERO);
							ps.setString(16, "0");
						}
						
						ps.setBigDecimal(17, row.getKdje());
						ps.setBigDecimal(18, row.getHsje());
						ps.setString(19, row.getFpdm());
						ps.setString(20, row.getFpbh());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------票据表插入结束");
					logger.info("--------------------------出纳表插入开始");
					for (ChailfSonPO row : sonList) {
						String cnSql = "INSERT INTO OAZJB_CNXX (OAZJB_CNXX_ID,OAZJB_CNXX_MXID,OAZJB_CNXX_XH,OAZJB_CNXX_ZFFS,"
								+ "OAZJB_CNXX_SKYH,OAZJB_CNXX_SKZH,OAZJB_CNXX_SKR,OAZJB_CNXX_ZFJE,OAZJB_CNXX_ZFSM,"
								+ "OAZJB_CNXX_CNFKYH,OAZJB_CNXX_CNFKZH)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(cnSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						ps.setBigDecimal(3, row.getXh());
						ps.setString(4, row.getZffs());
						ps.setString(5, row.getSkyh());
						ps.setString(6, row.getSkzh());
						ps.setString(7, row.getSkr());
						ps.setBigDecimal(8, row.getZfje());
						ps.setString(9, row.getZfsm());
						ps.setString(10, row.getCnfkyh());
						ps.setString(11, row.getCnfkzh());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------出纳表插入结束");
//					logger.info("--------------------------回单表插入开始");
//					for (ChailfBankPO row : bankList) {
//						String htSql = "INSERT INTO OAZJB_HTXX (OAZJB_HTXX_ID,OAZJB_HTXX_MXID,OAZJB_HTXX_XH,"
//								+ "OAZJB_HTXX_FKZH,OAZJB_HTXX_YHKD,OAZJB_HTXX_PZH)"
//								+ "VALUES (?,?,?,?,?,?)";
//
//						ps = conn.prepareStatement(htSql);
//						ps.setLong(1, row.getFormmainId());
//						ps.setLong(2, row.getId());
//						ps.setBigDecimal(3, row.getXh());
//						ps.setString(4, row.getFkzh());
//						ps.setString(5, row.getYhkd());
//						ps.setString(6, row.getPzh());
//						
//						rs = ps.executeUpdate();
//						
//						if (rs < 0) {
//							return;
//						}
//					}
//					logger.info("--------------------------回单表插入结束");

				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
						ps.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				return;
			} else if (huikuanCode.equals(templateCode)) {// --------内部资金拨付单
				List<HuiKuanSonPO> sonList = dealDataDao.findHuiKuanSonPO(Long.valueOf(formRecordId));
				
				for (HuiKuanSonPO row : sonList) {
					if (row.getYhhd() == null || "".equals(row.getYhhd().toString())) {
						return;
					}
				}
				
				HuiKuanPO huiKuanPO = dealDataDao.findHuiKuanPOById(Long.valueOf(formRecordId));
				
				Connection conn = BaseConnection.getConnection();
				PreparedStatement ps = null;
				int rs = 0;

				try {
					logger.info("--------------------------主表插入开始");
					String zbSql = "INSERT INTO OAZJB_ZB (OAZJB_ZB_ID,OAZJB_ZB_BDLX,OAZJB_ZB_HSDW,"
							+ "OAZJB_ZB_BXBM,OAZJB_ZB_SQRQ,OAZJB_ZB_FKSY,OAZJB_ZB_SFZX,OAZJB_ZB_HZJE,"
							+ "OAZJB_ZB_SQR,OAZJB_ZB_FKRQ,OAZJB_ZB_FKBM,OAZJB_ZB_FKDW,OAZJB_ZB_LSBH,OAZJB_ZB_LCDZ)"
							+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

					ps = conn.prepareStatement(zbSql);
					ps.setLong(1, huiKuanPO.getId());
					ps.setString(2, "4");
					ps.setString(3, huiKuanPO.getHsdw());
					ps.setString(4, huiKuanPO.getBxbm());
					if (huiKuanPO.getSqrq() != null) {
						java.sql.Date sqrq = new java.sql.Date(huiKuanPO.getSqrq().getTime());
						ps.setDate(5, sqrq);
					} else {
						ps.setDate(5, null);
					}
					ps.setString(6, huiKuanPO.getFksy());
					ps.setBigDecimal(7, huiKuanPO.getSfzx());
					ps.setBigDecimal(8, huiKuanPO.getHzje());
					ps.setString(9, huiKuanPO.getSqr());
					if (huiKuanPO.getFkrq() != null) {
						java.sql.Date fkrq = new java.sql.Date(huiKuanPO.getFkrq().getTime());
						ps.setDate(10, fkrq);
					} else {
						ps.setDate(10, null);
					}
					ps.setString(11, huiKuanPO.getFkbm());
					ps.setString(12, huiKuanPO.getFkdw());
					ps.setString(13, huiKuanPO.getLsbh());
					ps.setString(14, url);
					
					rs = ps.executeUpdate();
					
					if (rs < 0) {
						return;
					}
					logger.info("--------------------------主表插入结束");
					logger.info("--------------------------出纳表插入开始");
					for (HuiKuanSonPO row : sonList) {
						String cnSql = "INSERT INTO OAZJB_CNXX (OAZJB_CNXX_ID,OAZJB_CNXX_MXID,OAZJB_CNXX_XH,OAZJB_CNXX_ZFFS,"
								+ "OAZJB_CNXX_SKYH,OAZJB_CNXX_SKZH,OAZJB_CNXX_SKR,OAZJB_CNXX_ZFJE,OAZJB_CNXX_ZFSM,"
								+ "OAZJB_CNXX_CNFKYH,OAZJB_CNXX_CNFKZH,OAZJB_CNXX_BY1,OAZJB_CNXX_BY2,OAZJB_CNXX_BY3,OAZJB_CNXX_ZY)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(cnSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						ps.setBigDecimal(3, row.getXh());
						ps.setString(4, row.getZffs());
						ps.setString(5, row.getSkyh());
						ps.setString(6, row.getSkzh());
						ps.setString(7, row.getSkr());
						ps.setBigDecimal(8, row.getZfje());
						ps.setString(9, row.getZfsm());
						ps.setString(10, row.getCnfkyh());
						ps.setString(11, row.getCnfkzh());
						ps.setString(12, row.getKpmc());
						ps.setString(13, row.getZjyt());
						ps.setString(14, row.getYh());
						ps.setString(15, row.getZhaiyao());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------出纳表插入结束");

				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
						ps.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}

				return;
			}
		} else {
			// -----付款审批表流程模板编号
			if (fukuanCode.equals(templateCode)) {

				FukuanPO fukuanPO = dealDataDao.findFukuanPOById(Long.valueOf(formRecordId));
				List<FukuanSonPO> sonList = dealDataDao.findFukuanSonPO(Long.valueOf(formRecordId));
//				List<FukuanBankPO> bankList = dealDataDao.findFukuanBankPO(Long.valueOf(formRecordId));

				int i = 0;
				for (FukuanSonPO list : sonList) {
					PayItemPO payItemPO = getPayItemPO(list.getId().toString());
					if ("-1050385902029222795".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1110");
					} else if("-4621721173074426640".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1111");
					} else {
						payItemPO.setPayWay("");
					}
					payItemPO.setCompanyCode(fukuanPO.getHsdw());
					SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
					String dateString = sdf.format(fukuanPO.getSqrq());
					payItemPO.setAppDate(dateString);
					payItemPO.setAppUserName(fukuanPO.getSqr());

					payItemPO.setAmount(list.getZfje());
					payItemPO.setAbstract(list.getZfsm());
					payItemPO.setOppAccountCode(list.getSkzh());
					payItemPO.setOppAccountName(list.getSkr());
					payItemPO.setOppBankName(list.getSkyh());

					payItemPO.setBankAccount(list.getCnfkzh());
					payItemPO.setLinkUrl(urlCode);
//					payItemPO.setEntensionField1("1");

					payItemPOList.add(payItemPO);
					i = i + 1;
				}

				data.put("Bills", payItemPOList);
			} else if (zijinrzCode.equals(templateCode)) {// ---------资金入账申请表
				ZiJinRZPO ZiJinRZPO = dealDataDao.findZiJinRZPOById(Long.valueOf(formRecordId));
				List<ZiJinRZSonPO> sonList = dealDataDao.findZiJinRZSonPO(Long.valueOf(formRecordId));
//				List<ZiJinRZBankPO> bankList = dealDataDao.findZiJinRZBankPO(Long.valueOf(formRecordId));
				
				int i = 0;
				for (ZiJinRZSonPO list : sonList) {
					PayItemPO payItemPO = getPayItemPO(list.getId().toString());
					if ("-1050385902029222795".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1110");
					} else if("-4621721173074426640".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1111");
					} else {
						payItemPO.setPayWay("");
					}
					payItemPO.setCompanyCode(ZiJinRZPO.getHsdw());
					SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
					String dateString = sdf.format(ZiJinRZPO.getSqrq());
					payItemPO.setAppDate(dateString);
					payItemPO.setAppUserName(ZiJinRZPO.getSqr());

					payItemPO.setAmount(list.getZfje());
					payItemPO.setAbstract(list.getZfsm());
					payItemPO.setOppAccountCode(list.getSkzh());
					payItemPO.setOppAccountName(list.getSkr());
					payItemPO.setOppBankName(list.getSkyh());

					payItemPO.setBankAccount(list.getCnfkzh());
					payItemPO.setLinkUrl(urlCode);
//					payItemPO.setEntensionField1("6");

					payItemPOList.add(payItemPO);
					i = i + 1;
				}

				data.put("Bills", payItemPOList);
			} else if (neibuzjCode.equals(templateCode)) {// --------内部资金拨付单
				NeibuZjPO neibuZjPO = dealDataDao.findNeibuZjPOById(Long.valueOf(formRecordId));
				List<NeibuZjSonPO> sonList = dealDataDao.findNeibuZjSonPO(Long.valueOf(formRecordId));
//				List<NeibuZjBankPO> bankList = dealDataDao.findNeibuZjBankPO(Long.valueOf(formRecordId));

				int i = 0;
				for (NeibuZjSonPO list : sonList) {
					PayItemPO payItemPO = getPayItemPO(list.getId().toString());
					if ("-1050385902029222795".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1110");
					} else if("-4621721173074426640".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1111");
					} else {
						payItemPO.setPayWay("");
					}
					payItemPO.setCompanyCode(neibuZjPO.getHsdw());
					SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
					String dateString = sdf.format(neibuZjPO.getSqrq());
					payItemPO.setAppDate(dateString);
					payItemPO.setAppUserName(neibuZjPO.getSqr());

					payItemPO.setAmount(list.getZfje());
					payItemPO.setAbstract(list.getZfsm());
					payItemPO.setOppAccountCode(list.getSkzh());
					payItemPO.setOppAccountName(list.getSkr());
					payItemPO.setOppBankName(list.getSkyh());

					payItemPO.setBankAccount(list.getCnfkzh());
					payItemPO.setLinkUrl(urlCode);
//					payItemPO.setEntensionField1("4");

					payItemPOList.add(payItemPO);
					i = i + 1;
				}

				data.put("Bills", payItemPOList);
			} else if (hetongkCode.equals(templateCode)) {// --------合同款拨付审批单
				HetongPO hetongPO = dealDataDao.findHetongPOById(Long.valueOf(formRecordId));
				List<HetongSonPO> sonList = dealDataDao.findHetongSonPO(Long.valueOf(formRecordId));
//				List<HetongBankPO> bankList = dealDataDao.findHetongBankPO(Long.valueOf(formRecordId));

				int i = 0;
				for (HetongSonPO list : sonList) {
					PayItemPO payItemPO = getPayItemPO(list.getId().toString());
					if ("-1050385902029222795".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1110");
					} else if("-4621721173074426640".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1111");
					} else {
						payItemPO.setPayWay("");
					}
					payItemPO.setCompanyCode(hetongPO.getHsdw());
					SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
					String dateString = sdf.format(hetongPO.getSqrq());
					payItemPO.setAppDate(dateString);
					payItemPO.setAppUserName(hetongPO.getSqr());

					payItemPO.setAmount(list.getZfje());
					payItemPO.setAbstract(list.getZfsm());
					payItemPO.setOppAccountCode(list.getSkzh());
					payItemPO.setOppAccountName(list.getSkr());
					payItemPO.setOppBankName(list.getSkyh());

					payItemPO.setBankAccount(list.getCnfkzh());
					payItemPO.setLinkUrl(urlCode);
//					payItemPO.setEntensionField1("3");

					payItemPOList.add(payItemPO);
					i = i + 1;
				}

				data.put("Bills", payItemPOList);
			} else if (chailfCode.equals(templateCode)) {// -------差旅费报销单
				ChailfPO chailfPO = dealDataDao.findChailfPOById(Long.valueOf(formRecordId));
				List<ChailfSonPO> sonList = dealDataDao.findChailfSonPO(Long.valueOf(formRecordId));
//				List<ChailfBankPO> bankList = dealDataDao.findChailfBankPO(Long.valueOf(formRecordId));

				int i = 0;
				for (ChailfSonPO list : sonList) {
					PayItemPO payItemPO = getPayItemPO(list.getId().toString());
					if ("-1050385902029222795".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1110");
					} else if("-4621721173074426640".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1111");
					} else {
						payItemPO.setPayWay("");
					}
					payItemPO.setCompanyCode(chailfPO.getHsdw());
					SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
					String dateString = sdf.format(chailfPO.getSqrq());
					payItemPO.setAppDate(dateString);
					payItemPO.setAppUserName(chailfPO.getSqr());

					payItemPO.setAmount(list.getZfje());
					payItemPO.setAbstract(list.getZfsm());
					payItemPO.setOppAccountCode(list.getSkzh());
					payItemPO.setOppAccountName(list.getSkr());
					payItemPO.setOppBankName(list.getSkyh());

					payItemPO.setBankAccount(list.getCnfkzh());
					payItemPO.setLinkUrl(urlCode);
//					payItemPO.setEntensionField1("2");

					payItemPOList.add(payItemPO);
					i = i + 1;
				}

				data.put("Bills", payItemPOList);
			} else if (huikuanCode.equals(templateCode)) {// --------内部资金拨付单
				HuiKuanPO huikuanPO = dealDataDao.findHuiKuanPOById(Long.valueOf(formRecordId));
				List<HuiKuanSonPO> sonList = dealDataDao.findHuiKuanSonPO(Long.valueOf(formRecordId));

				int i = 0;
				for (HuiKuanSonPO list : sonList) {
					PayItemPO payItemPO = getPayItemPO(list.getId().toString());
					if ("-1050385902029222795".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1110");
					} else if("-4621721173074426640".equals(list.getZffs())) {
						payItemPO.setPayType("005");
						payItemPO.setPayWay("1111");
					} else {
						payItemPO.setPayWay("");
					}
					payItemPO.setCompanyCode(huikuanPO.getHsdw());
					SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
					String dateString = sdf.format(huikuanPO.getSqrq());
					payItemPO.setAppDate(dateString);
					payItemPO.setAppUserName(huikuanPO.getSqr());

					payItemPO.setAmount(list.getZfje());
					payItemPO.setAbstract(list.getZfsm());
					payItemPO.setOppAccountCode(list.getSkzh());
					payItemPO.setOppAccountName(list.getSkr());
					payItemPO.setOppBankName(list.getSkyh());

					payItemPO.setBankAccount(list.getCnfkzh());
					payItemPO.setLinkUrl(urlCode);
//					payItemPO.setEntensionField1("4");

					payItemPOList.add(payItemPO);
					i = i + 1;
				}

				data.put("Bills", payItemPOList);
			} else if (fapiaorzCode.equals(templateCode)) {
				FapiaoRzPO fapiaoRzPO = dealDataDao.findFapiaoRzPOById(Long.valueOf(formRecordId));
				List<FapiaoRzPJPO> pjList = dealDataDao.findFapiaoRzPJPO(Long.valueOf(formRecordId));
				
				Connection conn = BaseConnection.getConnection();
				PreparedStatement ps = null;
				int rs = 0;

				try {
					logger.info("--------------------------主表插入开始");
					String zbSql = "INSERT INTO OAZJB_ZB (OAZJB_ZB_ID,OAZJB_ZB_BDLX,OAZJB_ZB_HSDW,"
							+ "OAZJB_ZB_BXBM,OAZJB_ZB_SQRQ,OAZJB_ZB_FKSY,OAZJB_ZB_SFZX,OAZJB_ZB_HZJE,"
							+ "OAZJB_ZB_SQR,OAZJB_ZB_FKRQ,OAZJB_ZB_FKBM,OAZJB_ZB_FKDW,OAZJB_ZB_LSBH,OAZJB_ZB_LCDZ,OAZJB_ZB_BY1)"
							+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

					ps = conn.prepareStatement(zbSql);
					ps.setLong(1, fapiaoRzPO.getId());
					ps.setString(2, "7");
					ps.setString(3, fapiaoRzPO.getHsdw());
					ps.setString(4, fapiaoRzPO.getBxbm());
					java.sql.Date sqrq = new java.sql.Date(fapiaoRzPO.getSqrq().getTime());
					ps.setDate(5, sqrq);
					ps.setString(6, fapiaoRzPO.getFksy());
					ps.setBigDecimal(7, fapiaoRzPO.getSfzx());
					ps.setBigDecimal(8, fapiaoRzPO.getHzje());
					ps.setString(9, fapiaoRzPO.getSqr());
					if (fapiaoRzPO.getFkrq() != null) {
						java.sql.Date fkrq = new java.sql.Date(fapiaoRzPO.getFkrq().getTime());
						ps.setDate(10, fkrq);
					} else {
						ps.setDate(10, null);
					}
					ps.setString(11, fapiaoRzPO.getFkbm());
					ps.setString(12, fapiaoRzPO.getFkdw());
					ps.setString(13, fapiaoRzPO.getLsbh());
					ps.setString(14, url);
					ps.setString(15, fapiaoRzPO.getXmbh());
					
					rs = ps.executeUpdate();
					
					if (rs < 0) {
						return;
					}
					logger.info("--------------------------主表插入结束");
					logger.info("--------------------------票据表插入开始");
					for (FapiaoRzPJPO row : pjList) {
						String pjSql = "INSERT INTO OAZJB_PJXX (OAZJB_PJXX_ID,OAZJB_PJXX_MXID,OAZJB_PJXX_FYRX,OAZJB_PJXX_FYBM,"
								+ "OAZJB_PJXX_RYR,OAZJB_PJXX_FYXM,OAZJB_PJXX_FYLX,OAZJB_PJXX_FLXMBH,OAZJB_PJXX_BXBZ,"
								+ "OAZJB_PJXX_PJRX,OAZJB_PJXX_KPMC,OAZJB_PJXX_XFSBM,OAZJB_PJXX_KPRQ,OAZJB_PJXX_JE,"
								+ "OAZJB_PJXX_SE,OAZJB_PJXX_SL,OAZJB_PJXX_KDJE,OAZJB_PJXX_HSJE,OAZJB_PJXX_FPDM,OAZJB_PJXX_FPBH,OAZJB_PJXX_BY1,OAZJB_PJXX_BY2)"
								+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

						ps = conn.prepareStatement(pjSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						ps.setString(3, row.getFyrx());
						ps.setString(4, row.getFybm());
						ps.setString(5, row.getRyr());
						ps.setString(6, row.getFyxm());
						ps.setString(7, row.getFylx());
						ps.setString(8, row.getFlxmbh());
						ps.setString(9, row.getBxbz());
						ps.setString(10, row.getPjrx());
						ps.setString(11, row.getKpmc());
						ps.setString(12, row.getXfsbm());
						if (row.getKprq() != null) {
							java.sql.Date kprq = new java.sql.Date(row.getKprq().getTime());
							ps.setDate(13, kprq);
						} else {
							ps.setDate(13, null);
						}
						ps.setBigDecimal(14, row.getJe());
						if (row.getSl() != null) {
							ps.setBigDecimal(15, row.getSe());
							if (row.getSl().contains("%")) {
								int index = row.getSl().indexOf("%");
								String sl = row.getSl().substring(0, index).trim();
								BigDecimal divide = new BigDecimal(sl).divide(new BigDecimal(100));
								
								ps.setString(16, divide.toString());
							} else {
								ps.setString(16, row.getSl());
							}
						} else {
							ps.setBigDecimal(15, BigDecimal.ZERO);
							ps.setString(16, "0");
						}
						
						ps.setBigDecimal(17, row.getKdje());
						ps.setBigDecimal(18, row.getHsje());
						ps.setString(19, row.getFpdm());
						ps.setString(20, row.getFpbh());
						ps.setString(21, row.getZjyt());
						ps.setString(22, row.getCnmx());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					logger.info("--------------------------票据表插入结束");
					
				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
						ps.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				
				return;
			} else if (fapiaokjCode.equals(templateCode)) {
				FapiaoKjPO fapiaokjPO = dealDataDao.findFapiaoKjPOById(Long.valueOf(formRecordId));
				List<FapiaoKjPJPO> pjList = dealDataDao.findFapiaoKjPJPO(Long.valueOf(formRecordId));
//				List<FapiaoKjBankPO> bankList = dealDataDao.findFapiaoKjBankPO(Long.valueOf(formRecordId));
				
				Connection conn = BaseConnection.getConnection();
				PreparedStatement ps = null;
				int rs = 0;

				try {
					String zbSql = "INSERT INTO OAZJB_ZB (OAZJB_ZB_ID,OAZJB_ZB_BDLX,OAZJB_ZB_BXBM,OAZJB_ZB_SQRQ,"
							+ "OAZJB_ZB_HZJE,OAZJB_ZB_LCDZ)"
							+ "VALUES (?,?,?,?,?,?)";

					ps = conn.prepareStatement(zbSql);
					ps.setLong(1, fapiaokjPO.getId());
					ps.setString(2, "5");
					ps.setString(3, fapiaokjPO.getBxbm());
					if (fapiaokjPO.getSqrq() != null) {
						java.sql.Date sqrq = new java.sql.Date(fapiaokjPO.getSqrq().getTime());
						ps.setDate(4, sqrq);
					} else {
						ps.setDate(4, null);
					}
					ps.setBigDecimal(5, fapiaokjPO.getHzje());
					ps.setString(6, url);
					
					rs = ps.executeUpdate();
					
					if (rs < 0) {
						return;
					}
					
					for (FapiaoKjPJPO row : pjList) {
						String pjSql = "INSERT INTO OAZJB_PJXX (OAZJB_PJXX_ID,OAZJB_PJXX_MXID,OAZJB_PJXX_KPMC,"
								+ "OAZJB_PJXX_KDJE,OAZJB_PJXX_HSJE,OAZJB_PJXX_FPXM)"
								+ "VALUES (?,?,?,?,?,?)";

						ps = conn.prepareStatement(pjSql);
						ps.setLong(1, row.getFormmainId());
						ps.setLong(2, row.getId());
						ps.setString(3, row.getKpmc());
						ps.setBigDecimal(4, row.getKdje());
						ps.setBigDecimal(5, row.getHsje());
						ps.setString(6, row.getFpxm());
						
						rs = ps.executeUpdate();
						
						if (rs < 0) {
							return;
						}
					}
					
//					for (FapiaoKjBankPO row : bankList) {
//						String htSql = "INSERT INTO OAZJB_HTXX (OAZJB_HTXX_ID,OAZJB_HTXX_MXID,OAZJB_HTXX_XH,"
//								+ "OAZJB_HTXX_FKZH,OAZJB_HTXX_YHKD,OAZJB_HTXX_PZH)"
//								+ "VALUES (?,?,?,?,?,?)";
//
//						ps = conn.prepareStatement(htSql);
//						ps.setLong(1, row.getFormmainId());
//						ps.setLong(2, row.getId());
//						ps.setBigDecimal(3, row.getXh());
//						ps.setString(4, row.getFkzh());
//						ps.setString(5, row.getYhkd());
//						ps.setString(6, row.getPzh());
//						
//						rs = ps.executeUpdate();
//						
//						if (rs < 0) {
//							return;
//						}
//					}
					

				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
						ps.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				return;
			}
		}
		
		String jsonstr = JSONUtil.toJSONString(data);
		logger.info("--------------------------jsonstr:" + jsonstr);

		String zijinUrl = AppContext.getSystemProperty("gkcwplugin.zijinUrl");

		String param = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
				+ "<soap:Body>" + "<SendPaymentToGS xmlns=\"http://tempuri.org/\">" + "<jsonData>" + jsonstr
				+ "</jsonData>" + "</SendPaymentToGS>" + "  </soap:Body>" + "</soap:Envelope>";

		String result = new HttpUtils().httpPost(zijinUrl, param);
		logger.info("--------------------------result:" + result);

		try {
			// 创建一个DocumentBuilderFactory实例
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			// 获取DocumentBuilder实例
			DocumentBuilder builder = factory.newDocumentBuilder();

			// 将XML字符串转换为InputSource对象
			InputSource is = new InputSource(new StringReader(result));

			// 解析XML字符串并获取Document对象
			org.w3c.dom.Document document = builder.parse(is);
			String nodeValue = document.getElementsByTagName("SendPaymentToGSResult").item(0).getFirstChild()
					.getNodeValue();
			logger.info("--------------------------nodeValue:" + nodeValue);

			Map<String, ArrayList<Map<String, Object>>> parseJSONString = (Map<String, ArrayList<Map<String, Object>>>) JSONUtil
					.parseJSONString(nodeValue);
			logger.info("--------------------------parseJSONString:" + parseJSONString);

			ArrayList<Map<String, Object>> arrayList = parseJSONString.get("PayResult");

			for (Map<String, Object> row : arrayList) {
				logger.info("--------------------------row:" + row.toString());
				String res = (String) row.get("FLAG");
				if ("0".equals(res)) {
					return;
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public PayItemPO getPayItemPO(String formrecordId) {
		PayItemPO po = new PayItemPO();
		po.setBillID(formrecordId);
		po.setSrcSys("OA");
		po.setCurrency("01");
		po.setNote("");
		po.setBillType("0");
		po.setIdenticalBank("");
		po.setIdenticalCity("");
		po.setDescription("");

		return po;
	}
}
